From 08828ce82554b679e996076c6ecdf120b923f1f8 Mon Sep 17 00:00:00 2001 From: foudfou Date: Sun, 21 Apr 2013 14:17:29 +0200 Subject: [PATCH] for Thunderbird, base startup event on the last restored window's map. Unfortunately there is not equivalent "sessionstore-windows-restored" in TB yet. Many events related to windows are issued before windows are fully realized. "mail-startup-done"/"mail-tabs-session-restored" are issued by *each* window. "console-api-log-event" is not reliable and can be issued at relatively early stage on heavy configs. So that the best solution is probably to count restored windows ourselves... --- src/modules/FiretrayHandler.jsm | 35 +++++++++++++++++++++------- src/modules/linux/FiretrayWindow.jsm | 3 +++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm index 4b39800..b6a4c01 100644 --- a/src/modules/FiretrayHandler.jsm +++ b/src/modules/FiretrayHandler.jsm @@ -125,11 +125,16 @@ firetray.Handler = { firetray.Utils.addObservers(firetray.Handler, [ "xpcom-will-shutdown", "profile-change-teardown" ]); - if (this.appId === FIRETRAY_APP_DB['thunderbird']['id']) { - firetray.Utils.addObservers(firetray.Handler, [ "console-api-log-event" ]); - } else if (this.appId === FIRETRAY_APP_DB['firefox']['id'] || - this.appId === FIRETRAY_APP_DB['seamonkey']['id']) { + if (this.appId === FIRETRAY_APP_DB['firefox']['id'] || + this.appId === FIRETRAY_APP_DB['seamonkey']['id']) { firetray.Utils.addObservers(firetray.Handler, [ "sessionstore-windows-restored" ]); + } else if (this.appId === FIRETRAY_APP_DB['thunderbird']['id']) { + this.restoredWindowsCount = this.readTBRestoreWindowsCount(); + log.debug("restoredWindowsCount="+this.restoredWindowsCount); + if (!this.restoredWindowsCount) { + log.error("session file could not be read"); + this.restoredWindowsCount = 1; // default + } } else { firetray.Utils.addObservers(firetray.Handler, [ "final-ui-startup" ]); } @@ -188,6 +193,24 @@ firetray.Handler = { } }, + readTBRestoreWindowsCount: function() { + Cu.import("resource:///modules/IOUtils.js"); + let sessionFile = Services.dirsvc.get("ProfD", Ci.nsIFile); + sessionFile.append("session.json"); + var initialState = null; + if (sessionFile.exists()) { + let data = IOUtils.loadFileToString(sessionFile); + if (!data) return null; + try { + initialState = JSON.parse(data); + } catch(x) {} + if (!initialState) return null; + + return initialState.windows.length; + } + return null; + }, + // FIXME: this should definetely be done in Chat, but IM accounts // seem not be initialized at early stage (Exception... "'TypeError: // this._items is undefined' when calling method: @@ -219,10 +242,6 @@ firetray.Handler = { case "sessionstore-windows-restored": // sessionstore-windows-restored does not come after the realization of // all windows... so we wait a little - case "console-api-log-event": // one of the few events issued at later - // stage, once windows are realized - // second TB window also issues - // "mail-startup-done"/"mail-tabs-session-restored" case "final-ui-startup": // subject=ChromeWindow log.debug(topic+": "+subject+","+data); firetray.Utils.removeObservers(firetray.Handler, [ topic ]); diff --git a/src/modules/linux/FiretrayWindow.jsm b/src/modules/linux/FiretrayWindow.jsm index 8909af0..eae4f0c 100644 --- a/src/modules/linux/FiretrayWindow.jsm +++ b/src/modules/linux/FiretrayWindow.jsm @@ -592,6 +592,9 @@ firetray.Window = { if (!firetray.Handler.appStarted && firetray.Utils.prefService.getBoolPref('start_hidden')) { log.debug("start_hidden"); + if (firetray.Handler.restoredWindowsCount && + !--firetray.Handler.restoredWindowsCount) + firetray.Handler.startupDone(); firetray.Window.startupHide(xid); } gdk.gdk_window_remove_filter(firetray.Handler.gdkWindows.get(xid),