From 9dcd5faa4a0d050807e6b893d0c42d6bd98c0f24 Mon Sep 17 00:00:00 2001 From: foudfou Date: Thu, 26 Jan 2012 07:37:08 +0100 Subject: [PATCH] * rename pref 'scroll_to_hide' to 'scroll_hides' * refactoring of FiretrayVersionChange.jsm --- src/chrome/content/options.js | 4 +- src/chrome/content/options.xul | 4 +- src/defaults/preferences/prefs.js | 2 +- src/modules/FiretrayVersionChange.jsm | 151 ++++++++++++++++---------- 4 files changed, 101 insertions(+), 60 deletions(-) diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js index ab3e3cc..a5c3224 100644 --- a/src/chrome/content/options.js +++ b/src/chrome/content/options.js @@ -82,8 +82,8 @@ var firetrayUIOptions = { }, updateScrollOptions: function() { - let scroll_to_hide = document.getElementById("ui_scroll_to_hide").checked; - this.disableGroup(document.getElementById("ui_radiogroup_scroll"), !scroll_to_hide); + let scroll_hides = document.getElementById("ui_scroll_hides").checked; + this.disableGroup(document.getElementById("ui_radiogroup_scroll"), !scroll_hides); }, initMailControls: function() { diff --git a/src/chrome/content/options.xul b/src/chrome/content/options.xul index 1ed1f8c..874ec7b 100644 --- a/src/chrome/content/options.xul +++ b/src/chrome/content/options.xul @@ -24,7 +24,7 @@ - + @@ -65,7 +65,7 @@ - diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js index 70fbaa9..0da0d16 100644 --- a/src/defaults/preferences/prefs.js +++ b/src/defaults/preferences/prefs.js @@ -12,7 +12,7 @@ pref("extensions.firetray.hides_on_minimize", true); pref("extensions.firetray.hides_single_window", false); pref("extensions.firetray.start_hidden", false); pref("extensions.firetray.show_icon_on_hide", false); -pref("extensions.firetray.scroll_to_hide", true); +pref("extensions.firetray.scroll_hides", true); pref("extensions.firetray.scroll_mode", "down_hides"); pref("extensions.firetray.mail_notification", 1); diff --git a/src/modules/FiretrayVersionChange.jsm b/src/modules/FiretrayVersionChange.jsm index d87ff0f..1425434 100644 --- a/src/modules/FiretrayVersionChange.jsm +++ b/src/modules/FiretrayVersionChange.jsm @@ -8,7 +8,7 @@ Cu.import("resource://gre/modules/AddonManager.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://firetray/commons.js"); -const FIRETRAY_ID = "{9533f794-00b4-4354-aa15-c2bbda6989f8}"; +const FIRETRAY_ID = "{9533f794-00b4-4354-aa15-c2bbda6989f8}"; const FIRETRAY_SPLASH_PAGE = "http://foudfou.github.com/FireTray/"; /** @@ -16,6 +16,9 @@ const FIRETRAY_SPLASH_PAGE = "http://foudfou.github.com/FireTray/"; */ firetray.VersionChange = { + versionComparator: Cc["@mozilla.org/xpcom/version-comparator;1"] + .getService(Ci.nsIVersionComparator), + watch: function() { AddonManager.addAddonListener(this.uninstallListener); AddonManager.getAddonByID(FIRETRAY_ID, this.onVersionChange.bind(this)); @@ -37,56 +40,6 @@ firetray.VersionChange = { } }, - openMailTab: function() { - let mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane"); - if (mail3PaneWindow) { - var tabmail = mail3PaneWindow.document.getElementById("tabmail"); - mail3PaneWindow.focus(); - } - - if (tabmail) { - var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.initWithCallback({ notify: function() { - LOG("openMailTab"); - tabmail.openTab("contentTab", {contentPage: FIRETRAY_SPLASH_PAGE}); - }}, FIRETRAY_BROWSER_STARTUP_DELAY_MILLISECONDS, Ci.nsITimer.TYPE_ONE_SHOT); - } - }, - - 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"); - mainWindow.gBrowser.selectedTab = mainWindow.gBrowser.addTab(FIRETRAY_SPLASH_PAGE); - }, 1000); - } - }, - - 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"); - }, - - initPrefs: function(version) { - firetray.Utils.prefService.setBoolPref("firstrun", false); - firetray.Utils.prefService.setCharPref("installedVersion", version); - this.openTab(); - }, - onVersionChange: function(addon) { LOG("VERSION: "+addon.version); @@ -96,23 +49,111 @@ firetray.VersionChange = { if (firstrun) { WARN("FIRST RUN"); this.initPrefs(curVersion); + this.installHook(curVersion); } else { try { var installedVersion = firetray.Utils.prefService.getCharPref("installedVersion"); - var versionDelta = Cc["@mozilla.org/xpcom/version-comparator;1"].getService(Ci.nsIVersionComparator) - .compare(curVersion, installedVersion); + var versionDelta = this.versionComparator.compare(curVersion, installedVersion); if (versionDelta > 0) { firetray.Utils.prefService.setCharPref("installedVersion", curVersion); WARN("UPGRADE"); - this.openTab(); + this.upgradeHook(installedVersion, curVersion); } } catch (ex) { WARN("REINSTALL"); this.initPrefs(curVersion); + this.reinstallHook(curVersion); } } - } + }, + + initPrefs: function(version) { + firetray.Utils.prefService.setBoolPref("firstrun", false); + firetray.Utils.prefService.setCharPref("installedVersion", version); + }, + + installHook: function(curVersion) {}, + upgradeHook: function(prevVersion, curVersion) {}, + reinstallHook: function(curVersion) {} }; + + + +firetray.VersionChange.installHook = function(curVersion) { + this.openTab(); + this.tryEraseV03Options(); +}; + +firetray.VersionChange.upgradeHook = function(prevVersion, curVersion) { + this.openTab(); + this.tryEraseV03Options(); // FIXME: should check versions here +}; + +firetray.VersionChange.reinstallHook = function(curVersion) { + this.openTab(); +}; + +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) { + var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); + timer.initWithCallback({ notify: function() { + LOG("openMailTab"); + tabmail.openTab("contentTab", {contentPage: FIRETRAY_SPLASH_PAGE}); + }}, FIRETRAY_BROWSER_STARTUP_DELAY_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"); + mainWindow.gBrowser.selectedTab = mainWindow.gBrowser.addTab(FIRETRAY_SPLASH_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