[polari] app: Run initial setup on first run



commit c7fdaabd4a886fe664098a030e03aa556af2fe1b
Author: Danny Mølgaard <moelgaard dmp gmail com>
Date:   Mon Jan 16 20:02:25 2017 +0100

    app: Run initial setup on first run
    
    It's time to hook up the shiny new initial setup experience - when
    initial setup hasn't been run before and the user hasn't configured
    any rooms (with a previous version), show the initial setup window
    before the main application window.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772458

 src/application.js |   60 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 11 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index c1ce3ca..e2bc207 100644
--- a/src/application.js
+++ b/src/application.js
@@ -17,6 +17,7 @@ const TelepathyClient = imports.telepathyClient;
 const UserTracker = imports.userTracker;
 const Utils = imports.utils;
 const NetworksManager = imports.networksManager;
+const InitialSetup = imports.initialSetup;
 
 const MAX_RETRIES = 3;
 
@@ -280,24 +281,35 @@ var Application = new Lang.Class({
         this.activate_action('start-client', null);
 
         if (!this.active_window) {
-            let window = new MainWindow.MainWindow({ application: this });
-            window.connect('destroy', () => {
-                if (this._settings.get_boolean('run-in-background'))
-                    return;
-                this.emit('prepare-shutdown');
-            });
-            window.connect('notify::active-room',
-                           () => { this.emit('room-focus-changed'); });
-            window.connect('notify::is-active',
-                           () => { this.emit('room-focus-changed'); });
-            window.show_all();
+            if (this._needsInitialSetup()) {
+                let setupDialog = new InitialSetup.InitialSetupWindow({ application: this });
+                let id = this.connect('window-removed', () => {
+                    this.disconnect(id);
+                    this.activate();
+                });
+            } else {
+                let window = new MainWindow.MainWindow({ application: this });
+                window.connect('destroy', () => {
+                    if (this._settings.get_boolean('run-in-background'))
+                        return;
+                    this.emit('prepare-shutdown');
+                });
+                window.connect('notify::active-room',
+                               () => { this.emit('room-focus-changed'); });
+                window.connect('notify::is-active',
+                               () => { this.emit('room-focus-changed'); });
+            }
         }
+
         this.active_window.present();
     },
 
     vfunc_window_added: function(window) {
         this.parent(window);
 
+        if (!(window instanceof MainWindow.MainWindow))
+            return;
+
         let action = this.lookup_action('leave-current-room');
         window.connect('notify::active-room', () => {
             action.enabled = window.active_room != null;
@@ -406,6 +418,32 @@ var Application = new Lang.Class({
         });
     },
 
+    _touchFile: function(file) {
+        try {
+            file.get_parent().make_directory_with_parents(null);
+        } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS)) {
+            // not an error, carry on
+        }
+
+        let stream = file.create(0, null);
+        stream.close(null);
+    },
+
+    _needsInitialSetup: function() {
+        let f = Gio.File.new_for_path(GLib.get_user_cache_dir() +
+                                      '/polari/initial-setup-completed');
+        try {
+            this._touchFile(f);
+        } catch(e) {
+            if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS))
+                return false; // initial setup has completed
+            log('Failed to mark initial setup as completed: ' + e.message);
+        }
+
+        let savedRooms = this._settings.get_value('saved-channel-list');
+        return savedRooms.n_children() == 0;
+    },
+
     _updateUserListAction: function() {
         let room = this.active_window.active_room;
         let action = this.lookup_action('user-list');


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