[gnome-music/wip/jfelder/fix-goa-account-crash] scrobbler: Fix lastfm account removal



commit fcd5c05318318ca3b9566914b17fad6e4e0dbd97
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Sep 16 15:25:10 2019 +0200

    scrobbler: Fix lastfm account removal
    
    When, a GOA account is removed, the credentials and the account
    parameters are not reset. Thus, LastFmScrobbler will still try to
    scrobble even if the account does not exist anymore. This results in a
    crash.
    
    Fix the issue by resetting all GoaLastFM parameters when a Last.fm
    account is removed.
    
    Closes: #145

 gnomemusic/scrobbler.py | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/scrobbler.py b/gnomemusic/scrobbler.py
index e44fccd9..6cb4e986 100644
--- a/gnomemusic/scrobbler.py
+++ b/gnomemusic/scrobbler.py
@@ -48,12 +48,15 @@ class GoaLastFM(GObject.GObject):
     def __init__(self):
         super().__init__()
 
+        self._reset_attributes()
+        Goa.Client.new(None, self._new_client_callback)
+
+    def _reset_attributes(self):
         self._client = None
         self._account = None
         self._authentication = None
         self._disabled = True
-
-        Goa.Client.new(None, self._new_client_callback)
+        self._music_disabled_id = None
 
     @log
     def _new_client_callback(self, source, result):
@@ -64,14 +67,19 @@ class GoaLastFM(GObject.GObject):
                 Goa.Error(error.code), error.message))
             return
 
-        self._client.connect('account-added', self._goa_account_mutation)
-        self._client.connect('account-removed', self._goa_account_mutation)
+        self._client.connect("account-added", self._goa_account_added)
+        self._client.connect("account-removed", self._goa_account_removed)
         self._find_lastfm_account()
 
-    @log
-    def _goa_account_mutation(self, klass, args):
+    def _goa_account_added(self, client, obj):
         self._find_lastfm_account()
 
+    def _goa_account_removed(self, client, obj):
+        account = obj.get_account()
+        if account.props.provider_type == "lastfm":
+            self._account.disconnect(self._music_disabled_id)
+            self._reset_attributes()
+
     @log
     def _find_lastfm_account(self):
         accounts = self._client.get_accounts()
@@ -82,7 +90,7 @@ class GoaLastFM(GObject.GObject):
                 self._authentication = obj.get_oauth2_based()
                 self._account = account
                 self.disabled = self._account.props.music_disabled
-                self._account.connect(
+                self._music_disabled_id = self._account.connect(
                     'notify::music-disabled', self._goa_music_disabled)
                 break
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]