[polari/wip/raresv/blankState: 1/4] roomManager: add a way to track the first session



commit f246e29f01737ac5d9bded47b44e1e703edea94e
Author: Rares Visalom <rares visalom gmail com>
Date:   Fri Nov 25 00:04:14 2016 +0200

    roomManager: add a way to track the first session
    
    The isFirstRun property tracks whether or not this is the
    first time polari is opened, and the isRoomAdded property
    tracks whether or not rooms have been joined this session.
    The prepare-shutdown signal is tracked in order to check
    if we should delete the file or not.

 src/roomManager.js |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/roomManager.js b/src/roomManager.js
index f00065c..f3cebc5 100644
--- a/src/roomManager.js
+++ b/src/roomManager.js
@@ -40,6 +40,7 @@ const _RoomManager = new Lang.Class({
             else
                 this._app.lookup_action(a.name).connect('activate', a.handler);
         });
+        this._app.connect('prepare-shutdown', Lang.bind(this, this._validateInitialSetup));
 
         this._accountsMonitor.connect('account-enabled', (mon, account) => {
             this._restoreRooms(account.object_path);
@@ -52,6 +53,25 @@ const _RoomManager = new Lang.Class({
             this._removeSavedChannelsForAccount(account.object_path);
         });
         this._accountsMonitor.prepare(() => { this._restoreRooms(); });
+
+        this.isFirstRun = false;
+        let file = Gio.File.new_for_path(GLib.get_user_cache_dir() + '/polari/is-first-run');
+
+        try {
+            let stream = file.create(0, null);
+            stream.close(null);
+            this.isFirstRun = true;
+            log("created");
+        }
+        catch (e){
+            log("exception");
+            if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS)) {
+                this.isFirstRun = false;
+                log("already here");
+            }
+        }
+
+        this.isRoomAdded = false;
     },
 
     lookupRoom: function(id) {
@@ -186,6 +206,9 @@ const _RoomManager = new Lang.Class({
         if (present && this._app.active_window)
             this._app.active_window.active_room = room;
 
+        log("ensure room");
+        this.isRoomAdded = true;
+
         return room;
     },
 
@@ -201,6 +224,21 @@ const _RoomManager = new Lang.Class({
     _removeRoom: function(room) {
         if (this._rooms.delete(room.id))
             this.emit('room-removed', room);
+    },
+
+    _validateInitialSetup: function() {
+        log("validate initial setup " + this.isFirstRun + " " + this.isRoomAdded);
+        if (this.isFirstRun && !this.isRoomAdded) {
+            let file = Gio.File.new_for_path(GLib.get_user_cache_dir() + '/polari/is-first-run');
+
+            try {
+                log("file got deleted");
+                file.delete(null);
+            }
+            catch (e) {
+                log("Failed to remove is-first-run file: " + e.message);
+            }
+        }
     }
 });
 Signals.addSignalMethods(_RoomManager.prototype);


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