[polari/wip/fmuellner/misc-fixes: 37/41] accountsMonitor: Replace ::am-prepared signal with a method



commit eed49114881e8356d1969a6f795b2c4b93d9fa29
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Jul 30 17:33:11 2016 +0200

    accountsMonitor: Replace ::am-prepared signal with a method
    
    The signal was added in commit 5bfc81 to make sure that nothing interacts
    with the account manager before its factory has been set up. However using
    a signal for that purpose is problematic - it is only emitted when the
    account monitor's own prepare_async() call returns, so any signal handlers
    that are only connected after that call has completed will never run.
    
    We can fix this issue without reintroducing the ambiguity of multiple
    prepare_async() calls by providing our own prepare() method that runs
    its callback parameter either immediately or once the account manager
    is prepared.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769592

 src/accountsMonitor.js |   11 ++++++++++-
 src/application.js     |    9 ++-------
 src/chatroomManager.js |    8 +++-----
 src/roomList.js        |   11 +++++------
 4 files changed, 20 insertions(+), 19 deletions(-)
---
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index b290b0c..5cc9220 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -29,6 +29,7 @@ const AccountsMonitor = new Lang.Class({
         factory.add_channel_features([Tp.Channel.get_feature_quark_contacts()]);
         factory.add_contact_features([Tp.ContactFeature.ALIAS]);
 
+        this._preparedCallbacks = [];
         this._accountManager.prepare_async(null,
                                            Lang.bind(this, this._onPrepared));
     },
@@ -49,6 +50,14 @@ const AccountsMonitor = new Lang.Class({
         return this._accounts.get(accountPath);
     },
 
+    prepare: function(callback) {
+        let quark = Tp.AccountManager.get_feature_quark_core();
+        if (this._accountManager.is_prepared(quark))
+            callback();
+        else
+            this._preparedCallbacks.push(callback);
+    },
+
     _onPrepared: function(am, res) {
         try {
             am.prepare_finish(res);
@@ -75,7 +84,7 @@ const AccountsMonitor = new Lang.Class({
         am.connect('account-disabled',
                    Lang.bind(this, this._accountEnabledChanged));
 
-        this.emit('account-manager-prepared', am);
+        this._preparedCallbacks.forEach(callback => { callback(); });
     },
 
     _onPrepareShutdown: function() {
diff --git a/src/application.js b/src/application.js
index f5bf112..b47d764 100644
--- a/src/application.js
+++ b/src/application.js
@@ -160,14 +160,9 @@ const Application = new Lang.Class({
         let time = Utils.getTpEventTime();
         let uris = files.map(function(f) { return f.get_uri(); });
 
-        let quark = Tp.AccountManager.get_feature_quark_core();
-        if (this._accountsMonitor.accountManager.is_prepared(quark))
+        this._accountsMonitor.prepare(() => {
             this._openURIs(uris, time);
-        else
-            this._accountsMonitor.connect('account-manager-prepared', Lang.bind(this,
-                function(mon) {
-                    this._openURIs(uris, time);
-                }));
+        });
     },
 
     _openURIs: function(uris, time) {
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 1269027..2d14466 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -152,9 +152,8 @@ const _ChatroomManager = new Lang.Class({
 
         this._networkMonitor = Gio.NetworkMonitor.get_default();
         this._accountsMonitor = AccountsMonitor.getDefault();
-        this._accountsMonitor.connect('account-manager-prepared',
-                                      Lang.bind(this, this._onPrepared));
         this._amIsPrepared = false;
+        this._accountsMonitor.prepare(Lang.bind(this, this._onPrepared));
 
         this._app.connect('prepare-shutdown',
                           Lang.bind(this, this._onPrepareShutdown));
@@ -164,7 +163,7 @@ const _ChatroomManager = new Lang.Class({
         this._lastActiveRoom = null;
     },
 
-    _onPrepared: function(mon, am) {
+    _onPrepared: function() {
         let actions = [
             { name: 'join-room',
               handler: Lang.bind(this, this._onJoinActivated) },
@@ -183,7 +182,7 @@ const _ChatroomManager = new Lang.Class({
             this._app.lookup_action(a.name).connect('activate', a.handler);
         });
 
-        this._client = new Client(am, this);
+        this._client = new Client(this._accountsMonitor.accountManager, this);
 
         let filters = [];
 
@@ -214,7 +213,6 @@ const _ChatroomManager = new Lang.Class({
     },
 
     lateInit: function() {
-        let am = this._accountsMonitor.accountManager;
         let ready = this._amIsPrepared &&
             this._app.get_active_window() != null;
         if (!ready)
diff --git a/src/roomList.js b/src/roomList.js
index b62ec30..519b8c1 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -354,12 +354,6 @@ const RoomList = new Lang.Class({
         this._roomRows = new Map();
 
         this._accountsMonitor = AccountsMonitor.getDefault();
-        this._accountsMonitor.connect('account-manager-prepared', Lang.bind(this,
-            function(mon, am) {
-                let accounts = this._accountsMonitor.accounts;
-                for (let i = 0; i < accounts.length; i++)
-                    this._accountAdded(mon, accounts[i]);
-            }));
         this._accountsMonitor.connect('account-added',
                                       Lang.bind(this, this._accountAdded));
         this._accountsMonitor.connect('account-removed',
@@ -370,6 +364,11 @@ const RoomList = new Lang.Class({
         this._accountsMonitor.connect('account-disabled', (mon, account) => {
             this._updatePlaceholderVisibility(account);
         });
+        this._accountsMonitor.prepare(() => {
+            this._accountsMonitor.accounts.forEach(account => {
+                this._accountAdded(this._accountsMonitor, account);
+            });
+        });
 
         this._roomManager = ChatroomManager.getDefault();
         this._roomManager.connect('room-added',


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