mirror of
https://github.com/lutris/lutris.git
synced 2026-06-21 12:20:15 -04:00
Provide a way to disconnect the user and display connection status
This commit is contained in:
@@ -62,6 +62,15 @@
|
||||
<signal name="activate" handler="on_connect" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="disconnect_menuitem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Disconnect</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_disconnect" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="runners_menuitem">
|
||||
<property name="visible">True</property>
|
||||
@@ -582,21 +591,17 @@
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox2">
|
||||
<object class="GtkBox" id="status_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="status_label">
|
||||
<property name="visible">True</property>
|
||||
<object class="GtkImage" id="js1image">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="xpad">5</property>
|
||||
<property name="ypad">5</property>
|
||||
<property name="icon_name">input-gaming</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
@@ -612,7 +617,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage" id="js1image">
|
||||
<object class="GtkImage" id="js3image">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">input-gaming</property>
|
||||
</object>
|
||||
@@ -634,14 +639,43 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage" id="js3image">
|
||||
<object class="GtkLabel" id="status_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="xpad">5</property>
|
||||
<property name="ypad">5</property>
|
||||
<property name="label" translatable="yes">Lutris</property>
|
||||
<property name="lines">1</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="connection_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator" id="status_separator">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">input-gaming</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">4</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
||||
@@ -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'})
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user