From c3b32763486b0dd1ca3713ff1b29c7bdf7c7e9fa Mon Sep 17 00:00:00 2001 From: foudfou Date: Thu, 26 Jan 2012 11:37:41 +0100 Subject: [PATCH] fix: crash when quitting from popup menu --- src/modules/FiretrayHandler.jsm | 23 ++++++++++------------- src/modules/commons.js | 15 +++++++++++---- src/modules/gtk2/FiretrayPopupMenu.jsm | 5 ++--- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm index 25aea8d..1971897 100644 --- a/src/modules/FiretrayHandler.jsm +++ b/src/modules/FiretrayHandler.jsm @@ -137,7 +137,7 @@ firetray.Handler = { timer.initWithCallback({ notify: function() { firetray.Handler.appStarted = true; LOG("*** appStarted ***"); - }}, FIRETRAY_BROWSER_STARTUP_DELAY_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); + }}, FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); break; case "xpcom-will-shutdown": LOG("xpcom-will-shutdown"); @@ -228,8 +228,7 @@ firetray.Handler = { try { url = Services.prefs.getComplexValue(prefDomain, Components.interfaces.nsIPrefLocalizedString).data; - } catch (e) { - } + } catch (e) {} // use this if we can't find the pref if (!url) { @@ -248,11 +247,10 @@ firetray.Handler = { // FIXME: obviously we need to wait to avoid seg fault on jsapi.cpp:827 // 827 if (t->data.requestDepth) { - var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.initWithCallback({ notify: function() { + firetray.Utils.timer(function() { for(var key in firetray.Handler.windows) break; firetray.Handler.windows[key].chromeWin.open(home); - }}, FIRETRAY_BROWSER_NEW_WINDOW_DELAY_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); + }, FIRETRAY_DELAY_NOWAIT_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); } catch (x) { ERROR(x); } }, @@ -267,13 +265,12 @@ firetray.Handler = { quitApplication: function() { try { - let appStartup = Cc['@mozilla.org/toolkit/app-startup;1'] - .getService(Ci.nsIAppStartup); - appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); - } catch (x) { - ERROR(x); - return; - } + firetray.Utils.timer(function() { + let appStartup = Cc['@mozilla.org/toolkit/app-startup;1'] + .getService(Ci.nsIAppStartup); + appStartup.quit(Ci.nsIAppStartup.eAttemptQuit); + }, FIRETRAY_DELAY_NOWAIT_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); + } catch (x) { ERROR(x); } } }; // firetray.Handler diff --git a/src/modules/commons.js b/src/modules/commons.js index 4759423..a725c8b 100644 --- a/src/modules/commons.js +++ b/src/modules/commons.js @@ -7,8 +7,8 @@ var EXPORTED_SYMBOLS = "SEAMONKEY_ID", "getType", "isArray", "isEmpty", "strEquals", "FT_NOTIFICATION_DISABLED", "FT_NOTIFICATION_UNREAD_MESSAGE_COUNT", "FT_NOTIFICATION_NEWMAIL_ICON", "FT_NOTIFICATION_CUSTOM_ICON", - "FIRETRAY_BROWSER_STARTUP_DELAY_MILLISECONDS", - "FIRETRAY_BROWSER_NEW_WINDOW_DELAY_MILLISECONDS" ]; + "FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS", + "FIRETRAY_DELAY_NOWAIT_MILLISECONDS" ]; const Cc = Components.classes; const Ci = Components.interfaces; @@ -29,8 +29,8 @@ const FT_NOTIFICATION_UNREAD_MESSAGE_COUNT = 1; const FT_NOTIFICATION_NEWMAIL_ICON = 2; const FT_NOTIFICATION_CUSTOM_ICON = 3; -const FIRETRAY_BROWSER_STARTUP_DELAY_MILLISECONDS = 500; -const FIRETRAY_BROWSER_NEW_WINDOW_DELAY_MILLISECONDS = 0; +const FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS = 500; +const FIRETRAY_DELAY_NOWAIT_MILLISECONDS = 0; /** * firetray namespace. @@ -171,6 +171,13 @@ firetray.Utils = { return list; }, + timer: function(callback, delay, timerType) { + var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); + timer.initWithCallback({ notify: callback }, + delay, timerType); + }, + + tryCloseLibs: function(libs) { try { libs.forEach(function(lib) { diff --git a/src/modules/gtk2/FiretrayPopupMenu.jsm b/src/modules/gtk2/FiretrayPopupMenu.jsm index 207bf82..04b4f6c 100644 --- a/src/modules/gtk2/FiretrayPopupMenu.jsm +++ b/src/modules/gtk2/FiretrayPopupMenu.jsm @@ -19,8 +19,7 @@ if ("undefined" == typeof(firetray.StatusIcon)) firetray.PopupMenu = { initialized: false, - // pointers to JS functions. MUST LIVE DURING ALL THE EXECUTION - callbacks: {menuItemWindowActivate: {}}, + callbacks: {menuItemWindowActivate: {}}, // FIXME: try to store them into a ctypes array/struct. menu: null, menuSeparatorWindows: null, MIN_FONT_SIZE: 4, @@ -80,7 +79,7 @@ firetray.PopupMenu = { this.callbacks.menuItemQuitActivate = gobject.GCallback_t( firetray.Handler.quitApplication); - gobject.g_signal_connect(menuItemQuit, "activate", + gobject.g_signal_connect(menuItemQuit, "activate", firetray.PopupMenu.callbacks.menuItemQuitActivate, null); var menuWidget = ctypes.cast(this.menu, gtk.GtkWidget.ptr);