From c608058971bda3e34ad4d97103b072253fdf515e Mon Sep 17 00:00:00 2001 From: foudfou Date: Fri, 3 Aug 2012 15:53:36 +0200 Subject: [PATCH] add 'im' to mail server types and have VersionChange hooks applied synchronously This forces us to hard code the addon version :( --- src/defaults/preferences/prefs.js | 2 +- src/install.rdf | 2 +- src/modules/FiretrayHandler.jsm | 47 ++++++++++++++--------- src/modules/FiretrayMessaging.jsm | 4 +- src/modules/VersionChange.jsm | 64 ++++++++++++++++++++----------- src/modules/commons.js | 20 +++++----- 6 files changed, 85 insertions(+), 54 deletions(-) diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js index e02085b..89e27b5 100644 --- a/src/defaults/preferences/prefs.js +++ b/src/defaults/preferences/prefs.js @@ -31,4 +31,4 @@ pref("extensions.firetray.folder_count_recursive", true); // Ci.nsMsgFolderFlags.Archive|Drafts|Junk|Queue|SentMail|Trash|Virtual pref("extensions.firetray.excluded_folders_flags", 1077956384); // exposed in 1 tree, hence 2 branches: serverTypes, excludedAccounts -pref("extensions.firetray.mail_accounts", '{ "serverTypes": {"pop3":{"order":1,"excluded":false}, "imap":{"order":1,"excluded":false}, "movemail":{"order":2,"excluded":true}, "none":{"order":3,"excluded":false}, "rss":{"order":4,"excluded":true}, "nntp":{"order":5,"excluded":true}}, "excludedAccounts": [] }'); // JSON +pref("extensions.firetray.mail_accounts", '{ "serverTypes": {"pop3":{"order":1,"excluded":false}, "imap":{"order":1,"excluded":false}, "movemail":{"order":2,"excluded":true}, "none":{"order":3,"excluded":false}, "rss":{"order":4,"excluded":true}, "nntp":{"order":5,"excluded":true}, "im":{"order":6,"excluded":true}}, "excludedAccounts": [] }'); // JSON diff --git a/src/install.rdf b/src/install.rdf index e6aa128..b8f9633 100644 --- a/src/install.rdf +++ b/src/install.rdf @@ -5,7 +5,7 @@ true 2 FireTray - 0.4.2 + 0.4.2 Hua Luo, Francesco Solero, Foudil BRÉTEL Hua Luo, Francesco Solero (Firetray original authors) https://github.com/foudfou/firetray diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm index c64469f..806318e 100644 --- a/src/modules/FiretrayHandler.jsm +++ b/src/modules/FiretrayHandler.jsm @@ -27,10 +27,7 @@ if ("undefined" == typeof(firetray)) { // other global functions // (https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management) firetray.Handler = { - FILENAME_DEFAULT: null, - FILENAME_SUFFIX: "32.png", FILENAME_BLANK: null, - FILENAME_NEWMAIL: null, initialized: false, inMailApp: false, @@ -77,12 +74,15 @@ firetray.Handler = { this.inBrowserApp = true; F.LOG('inMailApp: '+this.inMailApp+', inBrowserApp: '+this.inBrowserApp); - this.FILENAME_DEFAULT = firetray.Utils.chromeToPath( - "chrome://firetray/skin/" + this.appName.toLowerCase() + this.FILENAME_SUFFIX); this.FILENAME_BLANK = firetray.Utils.chromeToPath( "chrome://firetray/skin/blank-icon.png"); - this.FILENAME_NEWMAIL = firetray.Utils.chromeToPath( - "chrome://firetray/skin/message-mail-new.png"); + + VersionChange.init(FIRETRAY_ID, FIRETRAY_VERSION, FIRETRAY_PREF_BRANCH); + VersionChange.addHook(["install", "upgrade", "reinstall"], firetray.VersionChangeHandler.showReleaseNotes); + VersionChange.addHook(["upgrade", "reinstall"], firetray.VersionChangeHandler.tryEraseOldOptions); + VersionChange.addHook(["upgrade", "reinstall"], firetray.VersionChangeHandler.correctMailNotificationType); + VersionChange.addHook(["upgrade", "reinstall"], firetray.VersionChangeHandler.addIMServerTypePrefMaybe); + VersionChange.applyHooksAndWatchUninstall(); firetray.StatusIcon.init(); firetray.Handler.showHideIcon(); @@ -105,11 +105,6 @@ firetray.Handler = { Services.obs.addObserver(this, "xpcom-will-shutdown", false); Services.obs.addObserver(this, "profile-change-teardown", false); - VersionChange.addHook(["install", "upgrade", "reinstall"], firetray.VersionChangeHandler.showReleaseNotes); - VersionChange.addHook(["upgrade", "reinstall"], firetray.VersionChangeHandler.tryEraseOldOptions); - VersionChange.addHook(["upgrade", "reinstall"], firetray.VersionChangeHandler.correctMailNotificationType); - VersionChange.watch(); - this.preventWarnOnClose(); this.initialized = true; @@ -348,10 +343,10 @@ firetray.PrefListener = new PrefListener( firetray.VersionChangeHandler = { - showReleaseNotes: function(ver) { - firetray.Handler.openTab(FIRETRAY_SPLASH_PAGE+"#v"+ver); - firetray.Handler.tryEraseOldOptions(); - firetray.Handler.correctMailNotificationType(); + showReleaseNotes: function() { + firetray.VersionChangeHandler.openTab(FIRETRAY_SPLASH_PAGE+"#v"+FIRETRAY_VERSION); + firetray.VersionChangeHandler.tryEraseOldOptions(); + firetray.VersionChangeHandler.correctMailNotificationType(); }, openTab: function(url) { @@ -412,16 +407,32 @@ firetray.VersionChangeHandler = { for (let i = 0, length = oldOptions.length; i= 0) ) + if (serverTypes[accountServer.type].excluded || + (excludedAccounts.indexOf(accountServer.key) >= 0)) continue; let rootFolder = accountServer.rootFolder; // nsIMsgFolder diff --git a/src/modules/VersionChange.jsm b/src/modules/VersionChange.jsm index 8fa7730..04fd1b7 100644 --- a/src/modules/VersionChange.jsm +++ b/src/modules/VersionChange.jsm @@ -5,7 +5,8 @@ const Ci = Components.interfaces; const Cu = Components.utils; Cu.import("resource://gre/modules/AddonManager.jsm"); -Cu.import("resource://firetray/commons.js"); +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://firetray/logging.jsm"); /** @@ -14,14 +15,27 @@ Cu.import("resource://firetray/commons.js"); */ var VersionChange = { - curVersion: null, + initialized: false, + addonId: null, + addonVersion: null, + addOnPrefs: null, + + init: function(id, version, prefBranch) { + F.LOG("VersionChange got: id="+id+" ver="+version+" prefBranch="+prefBranch); + this.addOnId = id; + this.addonVersion = version; + this.addOnPrefs = Services.prefs.getBranch(prefBranch); + + this.initialized = true; + }, versionComparator: Cc["@mozilla.org/xpcom/version-comparator;1"] .getService(Ci.nsIVersionComparator), - watch: function() { + applyHooksAndWatchUninstall: function() { + if (!this.initialized) throw "VersionChange not initialized"; + this.onVersionChange(this.addonVersion); // AddonManager.getAddonByID() async, whereas we need sync call AddonManager.addAddonListener(this.uninstallListener); - AddonManager.getAddonByID(FIRETRAY_ID, this.onVersionChange.bind(this)); F.LOG("version change watching enabled"); }, @@ -29,22 +43,21 @@ var VersionChange = { // detect reinstall later uninstallListener: { onUninstalling: function(addon) { - if (addon.id !== FIRETRAY_ID) return; - firetray.Utils.prefService.clearUserPref("installedVersion"); + if (addon.id !== this.addonId) return; + this.addOnPrefs.clearUserPref("installedVersion"); }, onOperationCancelled: function(addon) { - if (addon.id !== FIRETRAY_ID) return; + if (addon.id !== this.addonId) return; let beingUninstalled = (addon.pendingOperations & AddonManager.PENDING_UNINSTALL) != 0; if (beingUninstalled) - firetray.Utils.prefService.clearUserPref("installedVersion"); + this.addOnPrefs.clearUserPref("installedVersion"); } }, - onVersionChange: function(addon) { - F.LOG("VERSION: "+addon.version); + onVersionChange: function() { + F.LOG("VERSION: "+this.addonVersion); - this.curVersion = addon.version; - var firstrun = firetray.Utils.prefService.getBoolPref("firstrun"); + var firstrun = this.addOnPrefs.getBoolPref("firstrun"); if (firstrun) { F.LOG("FIRST RUN"); @@ -53,10 +66,10 @@ var VersionChange = { } else { try { - var installedVersion = firetray.Utils.prefService.getCharPref("installedVersion"); - var versionDelta = this.versionComparator.compare(this.curVersion, installedVersion); + var installedVersion = this.addOnPrefs.getCharPref("installedVersion"); + var versionDelta = this.versionComparator.compare(this.addonVersion, installedVersion); if (versionDelta > 0) { - firetray.Utils.prefService.setCharPref("installedVersion", this.curVersion); + this.addOnPrefs.setCharPref("installedVersion", this.addonVersion); F.LOG("UPGRADE"); this._applyHooks("upgrade"); } @@ -67,17 +80,18 @@ var VersionChange = { this._applyHooks("reinstall"); } } + }, initPrefs: function() { - firetray.Utils.prefService.setBoolPref("firstrun", false); - firetray.Utils.prefService.setCharPref("installedVersion", VersionChange.curVersion); + this.addOnPrefs.setBoolPref("firstrun", false); + this.addOnPrefs.setCharPref("installedVersion", VersionChange.addonVersion); }, - _hooks: [], // collection of callbacks {id: 1, categories: [], fun: function} + _hooks: [], // collection of callbacks {id: 1, categories: [], fun: function} addHook: function(categories, fun) { - if (!firetray.js.isArray(categories)) throw new CategoryError(); + if (Object.prototype.toString.call(categories) !== "[object Array]") throw new TypeError(); let id = this._hooks.push({})-1; this._hooks[id] = {id: id, categories: categories, fun: fun}; return id; @@ -89,10 +103,14 @@ var VersionChange = { }, _applyHooks: function(category) { - for (let i=0,len=this._hooks.length; i