diff --git a/data/ui/LutrisWindow.ui b/data/ui/LutrisWindow.ui index 51d34c28c..cdc729225 100644 --- a/data/ui/LutrisWindow.ui +++ b/data/ui/LutrisWindow.ui @@ -62,6 +62,15 @@ + + + True + False + Disconnect + True + + + True @@ -582,21 +591,17 @@ False 2 - + True False - - True + False - 0 - 5 - 5 + input-gaming - True - True - end + False + False 0 @@ -612,7 +617,7 @@ - + False input-gaming @@ -634,14 +639,43 @@ - + + True + False + 0 + 5 + 5 + Lutris + 1 + + + True + True + 4 + + + + + True + False + 1 + label + + + True + True + 5 + + + + + True False - input-gaming False - False - 4 + True + 6 diff --git a/lutris/api.py b/lutris/api.py index def530067..930280046 100644 --- a/lutris/api.py +++ b/lutris/api.py @@ -17,8 +17,11 @@ def read_api_key(): return with open(API_KEY_FILE_PATH, 'r') as token_file: api_string = token_file.read() - username, api_key = api_string.split(":") - return username, api_key + username, token = api_string.split(":") + return { + 'token': token, + 'username': username + } def connect(username, password): @@ -39,9 +42,19 @@ def connect(username, password): return False +def disconnect(): + if not os.path.exists(API_KEY_FILE_PATH): + return + os.remove(API_KEY_FILE_PATH) + + def get_library(): logger.debug("Fetching game library") - username, api_key = read_api_key() + credentials = read_api_key() + if not credentials: + return {} + username = credentials["username"] + api_key = credentials["token"] library_url = settings.SITE_URL + "api/v1/library/%s/" % username params = urllib.urlencode({'api_key': api_key, 'username': username, 'format': 'json'}) diff --git a/lutris/gui/dialogs.py b/lutris/gui/dialogs.py index 993d97e4e..c0301c479 100644 --- a/lutris/gui/dialogs.py +++ b/lutris/gui/dialogs.py @@ -239,7 +239,10 @@ class ClientLoginDialog(GtkBuilderDialog): if not token: NoticeDialog("Login failed") else: - self.emit('connected', token) + self.emit('connected', { + 'token': token, + 'username': username + }) self.dialog.destroy() diff --git a/lutris/gui/lutriswindow.py b/lutris/gui/lutriswindow.py index 36d74fccb..858fa581c 100644 --- a/lutris/gui/lutriswindow.py +++ b/lutris/gui/lutriswindow.py @@ -149,11 +149,16 @@ class LutrisWindow(object): self.switch_splash_screen() - if api.read_api_key(): - self.status_label.set_text("Connected to lutris.net") - self.sync_library() + connection_label = self.builder.get_object('connection_label') + credentials = api.read_api_key() + if credentials: + menuitem = self.builder.get_object('connect_menuitem') + self.on_connect_success(None, credentials) else: + menuitem = self.builder.get_object('disconnect_menuitem') + connection_label.set_text("Not connected") async_call(self.sync_icons, None) + menuitem.hide() @property def current_view_type(self): @@ -248,9 +253,21 @@ class LutrisWindow(object): login_dialog = dialogs.ClientLoginDialog() login_dialog.connect('connected', self.on_connect_success) - def on_connect_success(self, dialog, token): + def on_disconnect(self, *args): + api.disconnect() + disconnect_menuitem = self.builder.get_object('disconnect_menuitem') + disconnect_menuitem.hide() + + connect_menuitem = self.builder.get_object('connect_menuitem') + connect_menuitem.show() + + connection_label = self.builder.get_object('connection_label') + connection_label.set_text("Not connected") + + def on_connect_success(self, dialog, credentials): logger.info("Successfully connected to Lutris.net") - self.status_label.set_text("Connected") + connection_label = self.builder.get_object('connection_label') + connection_label.set_text("Connected as %s" % credentials["username"]) self.sync_library() def on_destroy(self, *args):