[polari] Disconnect accounts instead of leaving channels on shutdown



commit e43cd4b11b58a15662065b93a10a4eea4303f571
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Oct 10 16:34:30 2013 +0100

    Disconnect accounts instead of leaving channels on shutdown
    
    Leaving channels is horribly slow, resulting in a noticable disconnect
    between closing the window and actually exiting the application.
    Setting all active (IRC) accounts to offline instead is a lot faster,
    so do that instead. While this is mostly a workaround for a telepathy-idle
    issue, having an IRC connection running in the background is not actually
    useful, so this arguably the correct behavior anyway.

 src/accountsMonitor.js |   21 +++++++++++++++++++++
 src/chatroomManager.js |   18 ------------------
 2 files changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index 500388f..6774175 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -1,3 +1,4 @@
+const Gio = imports.gi.Gio;
 const Tp = imports.gi.TelepathyGLib;
 
 const Lang = imports.lang;
@@ -17,6 +18,10 @@ const AccountsMonitor = new Lang.Class({
     _init: function() {
         this._accounts = [];
 
+        this._app = Gio.Application.get_default();
+        this._app.connectJS('prepare-shutdown',
+                            Lang.bind(this, this._onPrepareShutdown));
+
         this._accountManager = Tp.AccountManager.dup();
         this._accountManager.prepare_async(null,
                                            Lang.bind(this, this._onPrepared));
@@ -48,6 +53,22 @@ const AccountsMonitor = new Lang.Class({
                    Lang.bind(this, this._accountEnabledChanged));
     },
 
+    _onPrepareShutdown: function() {
+        for (let i = 0; i < this._accounts.length; i++) {
+            let account = this._accounts[i];
+
+            let presence = Tp.ConnectionPresenceType.OFFLINE;
+            if (account.requested_presence_type == presence)
+                continue;
+
+            this._app.hold();
+            account.request_presence_async(presence, '', '',
+                Lang.bind(this, function() {
+                    this._app.release();
+                }));
+        }
+    },
+
     _shouldMonitorAccount: function(account) {
         return account.protocol_name == 'irc';
     },
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index c4d5787..047d633 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -22,8 +22,6 @@ const _ChatroomManager = new Lang.Class({
         this._activeRoom = null;
 
         this._app = Gio.Application.get_default();
-        this._app.connectJS('prepare-shutdown',
-                            Lang.bind(this, this._onPrepareShutdown));
 
         this._accountManager = Tp.AccountManager.dup();
 
@@ -35,22 +33,6 @@ 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);


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