Merge lp:~azzar1/software-properties/fix-1818992 into lp:software-properties

Proposed by Andrea Azzarone
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 1079
Merged at revision: 1079
Proposed branch: lp:~azzar1/software-properties/fix-1818992
Merge into: lp:software-properties
Diff against target: 56 lines (+16/-5)
1 file modified
softwareproperties/GoaAuth.py (+16/-5)
To merge this branch: bzr merge lp:~azzar1/software-properties/fix-1818992
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+364112@code.launchpad.net

Commit message

Don't segfault if GoaClient.new fails. Also make it async to not block the UI.

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'softwareproperties/GoaAuth.py'
--- softwareproperties/GoaAuth.py 2018-04-17 11:36:55 +0000
+++ softwareproperties/GoaAuth.py 2019-03-07 18:28:33 +0000
@@ -21,7 +21,9 @@
2121
22import gi22import gi
23gi.require_version('Goa', '1.0')23gi.require_version('Goa', '1.0')
24from gi.repository import Gio, Goa, GObject24from gi.repository import Gio, GLib, Goa, GObject
25
26import logging
2527
26class GoaAuth(GObject.GObject):28class GoaAuth(GObject.GObject):
2729
@@ -32,12 +34,21 @@
32 def __init__(self):34 def __init__(self):
33 GObject.GObject.__init__(self)35 GObject.GObject.__init__(self)
3436
35 self.goa_client = Goa.Client.new_sync(None)
36 self.account = None37 self.account = None
38 self.cancellable = Gio.Cancellable()
39 Goa.Client.new(self.cancellable, self._on_goa_client_ready)
3740
38 self.settings = Gio.Settings.new('com.ubuntu.SoftwareProperties')41 self.settings = Gio.Settings.new('com.ubuntu.SoftwareProperties')
39 self.settings.connect('changed::goa-account-id', self._on_settings_changed)42 self.settings.connect('changed::goa-account-id', self._on_settings_changed)
40 self._load()43
44 def _on_goa_client_ready(self, source, res):
45 try:
46 self.goa_client = Goa.Client.new_finish(res)
47 except GLib.Error as e:
48 logging.error('Failed to get a Gnome Online Account: {}'.format(e.message))
49 self.goa_client = None
50 else:
51 self._load()
4152
42 def login(self, account):53 def login(self, account):
43 assert(account)54 assert(account)
@@ -50,7 +61,7 @@
5061
51 @GObject.Property62 @GObject.Property
52 def token(self):63 def token(self):
53 if self.account is None:64 if self.account is None or self.goa_client is None:
54 return None65 return None
5566
56 obj = self.goa_client.lookup_by_id(self.account.props.id)67 obj = self.goa_client.lookup_by_id(self.account.props.id)
@@ -64,7 +75,7 @@
64 return pbased.call_get_password_sync('livepatch')75 return pbased.call_get_password_sync('livepatch')
6576
66 def _update_state_from_account_id(self, account_id):77 def _update_state_from_account_id(self, account_id):
67 if account_id:78 if account_id and self.goa_client is not None:
68 # Make sure the account-id is valid79 # Make sure the account-id is valid
69 obj = self.goa_client.lookup_by_id(account_id)80 obj = self.goa_client.lookup_by_id(account_id)
70 if obj is None:81 if obj is None:

Subscribers

People subscribed via source and target branches

to status/vote changes: