From f45f8f08c34497412a6b72f353dcdb0a18c3b285 Mon Sep 17 00:00:00 2001 From: foudfou Date: Mon, 30 Jan 2012 21:10:26 +0100 Subject: [PATCH] refactor VersionChange --- src/modules/FiretrayHandler.jsm | 72 ++++++++++++++++++ src/modules/FiretrayVersionChange.jsm | 101 +++----------------------- src/modules/commons.js | 11 ++- 3 files changed, 91 insertions(+), 93 deletions(-) diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm index 1971897..af83cd7 100644 --- a/src/modules/FiretrayHandler.jsm +++ b/src/modules/FiretrayHandler.jsm @@ -101,6 +101,17 @@ firetray.Handler = { Services.obs.addObserver(this, this.getAppStartupTopic(this.appId), false); Services.obs.addObserver(this, "xpcom-will-shutdown", false); + firetray.VersionChange.setInstallHook(function(ver) { + firetray.Handler.openTab(FIRETRAY_SPLASH_PAGE+"#"+ver); + firetray.Handler.tryEraseV03Options(); + }); + firetray.VersionChange.setUpgradeHook(function(ver) { + firetray.Handler.openTab(FIRETRAY_SPLASH_PAGE+"#"+ver); + firetray.Handler.tryEraseV03Options(); // FIXME: should check versions here + }); + firetray.VersionChange.setReinstallHook(function(ver) { + firetray.Handler.openTab(FIRETRAY_SPLASH_PAGE+"#"+ver); + }); firetray.VersionChange.watch(); this.initialized = true; @@ -263,6 +274,67 @@ firetray.Handler = { } catch (x) { ERROR(x); } }, + openTab: function(url) { + let appId = Services.appinfo.ID; + if (appId === THUNDERBIRD_ID) + this.openMailTab(url); + else if (appId === FIREFOX_ID || appId === SEAMONKEY_ID) + this.openBrowserTab(url); + else + ERROR("unsupported application"); + }, + + openMailTab: function(url) { + let mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane"); + if (mail3PaneWindow) { + var tabmail = mail3PaneWindow.document.getElementById("tabmail"); + mail3PaneWindow.focus(); + } + + if (tabmail) { + firetray.Utils.timer(function() { + LOG("openMailTab"); + tabmail.openTab("contentTab", {contentPage: url}); + }, FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); + } + }, + + openBrowserTab: function(url) { + let win = Services.wm.getMostRecentWindow("navigator:browser"); + WARN("WIN="+win); + if (win) { + var mainWindow = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIWebNavigation) + .QueryInterface(Components.interfaces.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindow); + + mainWindow.setTimeout(function(win){ + LOG("openBrowser"); + mainWindow.gBrowser.selectedTab = mainWindow.gBrowser.addTab(url); + }, 1000); + } + }, + + tryEraseV03Options: function() { + let v03options = [ + "close_to_tray", "minimize_to_tray", "start_minimized", "confirm_exit", + "restore_to_next_unread", "mail_count_type", "show_mail_count", + "dont_count_spam", "dont_count_archive", "dont_count_drafts", + "dont_count_sent", "dont_count_templates", "show_mail_notification", + "show_icon_only_minimized", "use_custom_normal_icon", + "use_custom_special_icon", "custom_normal_icon", "custom_special_icon", + "text_color", "scroll_to_hide", "scroll_action", "grab_multimedia_keys", + "hide_show_mm_key", "accounts_to_exclude" ]; + + for (let i = 0, length = v03options.length; i 0) { firetray.Utils.prefService.setCharPref("installedVersion", this.curVersion); WARN("UPGRADE"); - this.upgradeHook(); + this.upgradeHook(this.curVersion); } } catch (ex) { WARN("REINSTALL"); this.initPrefs(); - this.reinstallHook(); + this.reinstallHook(this.curVersion); } } }, @@ -75,87 +74,11 @@ firetray.VersionChange = { firetray.Utils.prefService.setCharPref("installedVersion", firetray.VersionChange.curVersion); }, - installHook: function() {}, - upgradeHook: function() {}, - reinstallHook: function() {} + installHook: function(ver){}, + upgradeHook: function(ver){}, + reinstallHook: function(ver){}, + setInstallHook: function(fun) {this.installHook = fun;}, + setUpgradeHook: function(fun) {this.upgradeHook = fun;}, + setReinstallHook: function(fun) {this.reinstallHook = fun;} }; - - - -firetray.VersionChange.installHook = function() { - this.openTab(); - this.tryEraseV03Options(); -}; - -firetray.VersionChange.upgradeHook = function() { - this.openTab(); - this.tryEraseV03Options(); // FIXME: should check versions here -}; - -firetray.VersionChange.reinstallHook = function() { - this.openTab(Version); -}; - -firetray.VersionChange.openTab = function() { - let appId = Services.appinfo.ID; - if (appId === THUNDERBIRD_ID) - this.openMailTab(); - else if (appId === FIREFOX_ID || appId === SEAMONKEY_ID) - this.openBrowserTab(); - else - ERROR("unsupported application"); -}; - -firetray.VersionChange.openMailTab = function() { - let mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane"); - if (mail3PaneWindow) { - var tabmail = mail3PaneWindow.document.getElementById("tabmail"); - mail3PaneWindow.focus(); - } - - if (tabmail) { - firetray.Utils.timer(function() { - LOG("openMailTab"); - let page = FIRETRAY_SPLASH_PAGE+"#"+firetray.VersionChange.curVersion; - tabmail.openTab("contentTab", {contentPage: page}); - }, FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); - } -}; - -firetray.VersionChange.openBrowserTab = function() { - let win = Services.wm.getMostRecentWindow("navigator:browser"); - WARN("WIN="+win); - if (win) { - var mainWindow = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebNavigation) - .QueryInterface(Components.interfaces.nsIDocShellTreeItem) - .rootTreeItem - .QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIDOMWindow); - - mainWindow.setTimeout(function(win){ - LOG("openBrowser"); - let page = FIRETRAY_SPLASH_PAGE+"#"+firetray.VersionChange.curVersion; - mainWindow.gBrowser.selectedTab = mainWindow.gBrowser.addTab(page); - }, 1000); - } -}; - -firetray.VersionChange.tryEraseV03Options = function() { - let v03options = [ - "close_to_tray", "minimize_to_tray", "start_minimized", "confirm_exit", - "restore_to_next_unread", "mail_count_type", "show_mail_count", - "dont_count_spam", "dont_count_archive", "dont_count_drafts", - "dont_count_sent", "dont_count_templates", "show_mail_notification", - "show_icon_only_minimized", "use_custom_normal_icon", - "use_custom_special_icon", "custom_normal_icon", "custom_special_icon", - "text_color", "scroll_to_hide", "scroll_action", "grab_multimedia_keys", - "hide_show_mm_key", "accounts_to_exclude" ]; - - for (let i = 0, length = v03options.length; i