From 2947b921489937e6fb8ea8d9634510585b78bcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 6 Oct 2011 02:47:18 +0200 Subject: [PATCH] user-menu: Restore previous session presence at startup Save the session presence in GSettings and restore it on startup. https://bugzilla.gnome.org/show_bug.cgi?id=659021 --- data/org.gnome.shell.gschema.xml.in | 4 ++++ js/ui/userMenu.js | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/data/org.gnome.shell.gschema.xml.in b/data/org.gnome.shell.gschema.xml.in index a848818d2..82b0c331d 100644 --- a/data/org.gnome.shell.gschema.xml.in +++ b/data/org.gnome.shell.gschema.xml.in @@ -54,6 +54,10 @@ 0 <_summary> + + 0 + <_summary> + diff --git a/js/ui/userMenu.js b/js/ui/userMenu.js index 85d98028e..d6e30af78 100644 --- a/js/ui/userMenu.js +++ b/js/ui/userMenu.js @@ -158,10 +158,11 @@ IMStatusChooserItem.prototype = { Lang.bind(this, this._changeIMStatus)); this._presence = new GnomeSession.Presence(); - this._presence.getStatus(Lang.bind(this, this._sessionStatusChanged)); this._presence.connect('StatusChanged', Lang.bind(this, this._sessionStatusChanged)); + this._sessionPresenceRestored = false; + this._imPresenceRestored = false; this._currentPresence = undefined; this._accountMgr = Tp.AccountManager.dup() @@ -267,12 +268,20 @@ IMStatusChooserItem.prototype = { }, _IMStatusChanged: function(accountMgr, presence, status, message) { + if (!this._imPresenceRestored) + this._imPresenceRestored = true; + if (presence == this._currentPresence) return; this._currentPresence = presence; this._setComboboxPresence(presence); + if (!this._sessionPresenceRestored) { + this._presence.getStatus(Lang.bind(this, this._sessionStatusChanged)); + return; + } + if (presence == Tp.ConnectionPresenceType.AVAILABLE) this._presence.setStatus(GnomeSession.PresenceStatus.AVAILABLE); @@ -349,6 +358,20 @@ IMStatusChooserItem.prototype = { }, _sessionStatusChanged: function(sessionPresence, sessionStatus) { + if (!this._imPresenceRestored) + return; + + if (!this._sessionPresenceRestored) { + let savedStatus = global.settings.get_int('saved-session-presence'); + if (sessionStatus != savedStatus) { + this._presence.setStatus(savedStatus); + return; + } + this._sessionPresenceRestored = true; + } + + global.settings.set_int('saved-session-presence', sessionStatus); + let [presence, s, msg] = this._accountMgr.get_most_available_presence(); let newPresence, status;