1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-08-13 15:53:47 -04:00

refactor VersionChange

This commit is contained in:
foudfou 2012-01-30 21:10:26 +01:00
parent d116bdd473
commit f45f8f08c3
3 changed files with 91 additions and 93 deletions

View File

@ -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<length; ++i) {
try {
firetray.Utils.prefService.clearUserPref(v03options[i]);
} catch (x) {}
}
},
quitApplication: function() {
try {
firetray.Utils.timer(function() {

View File

@ -5,14 +5,13 @@ const Ci = Components.interfaces;
const Cu = Components.utils;
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_SPLASH_PAGE = "http://foudfou.github.com/FireTray/";
/**
* handles version changes, by doing things like opening a tab for release notes
* handles version changes.
* use setInstallHook(), setUpgradeHook(), setReinstallHook()
* http://mike.kaply.com/2011/02/02/running-add-on-code-at-first-run-and-upgrade/
*/
firetray.VersionChange = {
curVersion: null,
@ -50,7 +49,7 @@ firetray.VersionChange = {
if (firstrun) {
WARN("FIRST RUN");
this.initPrefs();
this.installHook();
this.installHook(this.curVersion);
} else {
try {
@ -59,13 +58,13 @@ firetray.VersionChange = {
if (versionDelta > 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<length; ++i) {
try {
firetray.Utils.prefService.clearUserPref(v03options[i]);
} catch (x) {}
}
};

View File

@ -4,9 +4,10 @@
provided by this module */
var EXPORTED_SYMBOLS =
[ "firetray", "LOG", "WARN", "ERROR", "FIREFOX_ID", "THUNDERBIRD_ID",
"SEAMONKEY_ID", "getType", "isArray", "isEmpty", "strEquals",
"FT_NOTIFICATION_DISABLED", "FT_NOTIFICATION_UNREAD_MESSAGE_COUNT",
"FT_NOTIFICATION_NEWMAIL_ICON", "FT_NOTIFICATION_CUSTOM_ICON",
"SEAMONKEY_ID", "FIRETRAY_ID", "FIRETRAY_SPLASH_PAGE", "getType",
"isArray", "isEmpty", "strEquals", "FT_NOTIFICATION_DISABLED",
"FT_NOTIFICATION_UNREAD_MESSAGE_COUNT", "FT_NOTIFICATION_NEWMAIL_ICON",
"FT_NOTIFICATION_CUSTOM_ICON",
"FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
"FIRETRAY_DELAY_NOWAIT_MILLISECONDS" ];
@ -24,6 +25,9 @@ const SUNBIRD_ID = "{718e30fb-e89b-41dd-9da7-e25a45638b28}";
const SEAMONKEY_ID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}";
const CHATZILLA_ID = "{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}";
const FIRETRAY_ID = "{9533f794-00b4-4354-aa15-c2bbda6989f8}";
const FIRETRAY_SPLASH_PAGE = "http://foudfou.github.com/FireTray/";
const FT_NOTIFICATION_DISABLED = 0;
const FT_NOTIFICATION_UNREAD_MESSAGE_COUNT = 1;
const FT_NOTIFICATION_NEWMAIL_ICON = 2;
@ -177,7 +181,6 @@ firetray.Utils = {
delay, timerType);
},
tryCloseLibs: function(libs) {
try {
libs.forEach(function(lib) {