[polari] chatroomManager: Properly leave all channels on exit



commit 8581ba2b870432598bcc536df6b1c4d88bf73797
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Jul 27 00:29:53 2013 +0200

    chatroomManager: Properly leave all channels on exit
    
    We currently do this in chatView, but there'll be other tasks
    chatroomManager should perform at shutdown, so move closing
    channels there as well.

 src/chatView.js        |   11 -----------
 src/chatroomManager.js |   26 ++++++++++++++++++++++----
 2 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 182bea1..6ef924a 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -179,17 +179,6 @@ const ChatView = new Lang.Class({
         for (let i = 0; i < this._roomSignals.length; i++)
             this._room.disconnect(this._roomSignals[i]);
         this._roomSignals = [];
-
-        if (!this._room.channel.get_invalidated()) {
-            let app = Gio.Application.get_default();
-            app.hold();
-            this._room.channel.connect('invalidated',
-                function() {
-                    app.release();
-                });
-            this._room.channel.leave_async(Tp.ChannelGroupChangeReason.NONE,
-                                           '', null);
-        }
     },
 
     _updateIndent: function() {
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 6a4ad11..610ac48 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -20,6 +20,10 @@ const _ChatroomManager = new Lang.Class({
         this._rooms = {};
         this._activeRoom = null;
 
+        this._app = Gio.Application.get_default();
+        this._app.connectJS('prepare-shutdown',
+                            Lang.bind(this, this._onPrepareShutdown));
+
         this._accountManager = Tp.AccountManager.dup();
 
         let factory = this._accountManager.get_factory();
@@ -29,12 +33,27 @@ const _ChatroomManager = new Lang.Class({
                                            Lang.bind(this, this._onPrepared));
     },
 
+    _onPrepareShutdown: function() {
+        for (let id in this._rooms) {
+            let room = this._rooms[id];
+
+            if (room.channel.get_invalidated())
+                continue;
+
+            this._app.hold();
+            room.channel.connect('invalidated', Lang.bind(this,
+                function() {
+                    this._app.release();
+                }));
+            room.channel.leave_async(Tp.ChannelGroupChangeReason.NONE, '', null);
+        }
+    },
+
     _onPrepared: function(am, res) {
         try {
             am.prepare_finish(res);
         } catch(e) {
-            let app = Gio.Application.get_default();
-            app.release(); // no point in carrying on
+            this._app.release(); // no point in carrying on
         }
 
         this._observer = Tp.SimpleObserver.new_with_am(am, true,
@@ -122,8 +141,7 @@ const _ChatroomManager = new Lang.Class({
                 //channel.join_async('', null);
                 this.setActiveRoom(room);
             }));
-        let app = Gio.Application.get_default();
-        app.get_active_window().present_with_time(userTime);
+        this._app.get_active_window().present_with_time(userTime);
     },
 
     _addRoom: function(room) {


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