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...
This commit is contained in:
foudfou 2013-04-21 14:17:29 +02:00
parent c4c5a3425b
commit 08828ce825
2 changed files with 30 additions and 8 deletions

View File

@ -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 ]);

View File

@ -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),