From 6c280606b2fc0dab1a544a120589c97c2836d174 Mon Sep 17 00:00:00 2001 From: "dries.k" Date: Thu, 3 Feb 2022 19:18:31 +0100 Subject: [PATCH] use QUrl to construct the websocket url --- gotify_tray/gotify/api.py | 3 +-- gotify_tray/gotify/listener.py | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gotify_tray/gotify/api.py b/gotify_tray/gotify/api.py index 166e8c1..b832507 100644 --- a/gotify_tray/gotify/api.py +++ b/gotify_tray/gotify/api.py @@ -69,8 +69,7 @@ class GotifyApplication(GotifySession): class GotifyClient(GotifySession): def __init__(self, url: str, client_token: str): super(GotifyClient, self).__init__(url, client_token) - self.hostname = self.url.lstrip("https://").lstrip("http://") - self.listener = Listener(self.hostname, client_token) + self.listener = Listener(url, client_token) """ Application diff --git a/gotify_tray/gotify/listener.py b/gotify_tray/gotify/listener.py index a1edabd..dc19656 100644 --- a/gotify_tray/gotify/listener.py +++ b/gotify_tray/gotify/listener.py @@ -17,13 +17,16 @@ class Listener(QtCore.QThread): opened = QtCore.pyqtSignal() closed = QtCore.pyqtSignal(int, str) - def __init__(self, hostname: str, client_token: str): + def __init__(self, url: str, client_token: str): super(Listener, self).__init__() - self.hostname = hostname - self.client_token = client_token + + qurl = QtCore.QUrl(url) + qurl.setScheme("wss") + qurl.setPath("/stream") + qurl.setQuery(f"token={client_token}") self.ws = websocket.WebSocketApp( - f"wss://{self.hostname}/stream?token={self.client_token}", + qurl.toString(), on_message=self._on_message, on_error=self._on_error, on_open=self._on_open,