[polari/gnome-3-20] networksManager: Load initial networks list synchronously



commit c3524833ba9cbea4a5f54ccd7070e3c732d7df5d
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jun 3 17:09:12 2016 +0200

    networksManager: Load initial networks list synchronously
    
    Loading a file from a resource is super-fast as it does not involve IO,
    so there's no real reason to do the operation asynchronously, in
    particular as we initialize the networks manager singleton before any UI
    is shown. It does open the door for race conditions on startup though,
    which we can easily avoid by loading the initial list synchronously.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766935

 src/application.js     |    4 ----
 src/networksManager.js |    8 +++++++-
 2 files changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index a2d7242..9eb6096 100644
--- a/src/application.js
+++ b/src/application.js
@@ -191,10 +191,6 @@ const Application = new Lang.Class({
             if (!success)
                 return;
 
-            // When launching Polari via a URL, there is a potential race
-            // condition between networksManager and AccountsManager here. If
-            // AccountsManager finishes first, networksManager's list of
-            // servers would be empty and hence no matches would be found.
             let matchedId = this._networksManager.findByServer(server);
             let matches = Object.keys(map).filter(function(a) {
                 return GLib.ascii_strcasecmp(map[a].server, server) == 0 ||
diff --git a/src/networksManager.js b/src/networksManager.js
index 2ac7584..f09b081 100644
--- a/src/networksManager.js
+++ b/src/networksManager.js
@@ -21,7 +21,13 @@ const NetworksManager = new Lang.Class({
 
         let uri = 'resource:///org/gnome/Polari/data/networks.json';
         let file = Gio.File.new_for_uri(uri);
-        file.load_contents_async(null, Lang.bind(this, this._onContentsReady));
+        let success, data;
+        try {
+            [success, data, ] = file.load_contents(null);
+            this._parseNetworks(data);
+        } catch(e) {
+            log('Failed to load network list: ' + e.message);
+        }
     },
 
     _onContentsReady: function(f, res) {


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