mirror of
https://github.com/moparisthebest/FireTray
synced 2024-11-10 11:05:07 -05:00
refactor VersionChange
This commit is contained in:
parent
d116bdd473
commit
f45f8f08c3
@ -101,6 +101,17 @@ firetray.Handler = {
|
|||||||
Services.obs.addObserver(this, this.getAppStartupTopic(this.appId), false);
|
Services.obs.addObserver(this, this.getAppStartupTopic(this.appId), false);
|
||||||
Services.obs.addObserver(this, "xpcom-will-shutdown", 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();
|
firetray.VersionChange.watch();
|
||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
@ -263,6 +274,67 @@ firetray.Handler = {
|
|||||||
} catch (x) { ERROR(x); }
|
} 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() {
|
quitApplication: function() {
|
||||||
try {
|
try {
|
||||||
firetray.Utils.timer(function() {
|
firetray.Utils.timer(function() {
|
||||||
|
@ -5,14 +5,13 @@ const Ci = Components.interfaces;
|
|||||||
const Cu = Components.utils;
|
const Cu = Components.utils;
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/AddonManager.jsm");
|
Cu.import("resource://gre/modules/AddonManager.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
|
||||||
Cu.import("resource://firetray/commons.js");
|
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 = {
|
firetray.VersionChange = {
|
||||||
curVersion: null,
|
curVersion: null,
|
||||||
@ -50,7 +49,7 @@ firetray.VersionChange = {
|
|||||||
if (firstrun) {
|
if (firstrun) {
|
||||||
WARN("FIRST RUN");
|
WARN("FIRST RUN");
|
||||||
this.initPrefs();
|
this.initPrefs();
|
||||||
this.installHook();
|
this.installHook(this.curVersion);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -59,13 +58,13 @@ firetray.VersionChange = {
|
|||||||
if (versionDelta > 0) {
|
if (versionDelta > 0) {
|
||||||
firetray.Utils.prefService.setCharPref("installedVersion", this.curVersion);
|
firetray.Utils.prefService.setCharPref("installedVersion", this.curVersion);
|
||||||
WARN("UPGRADE");
|
WARN("UPGRADE");
|
||||||
this.upgradeHook();
|
this.upgradeHook(this.curVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
WARN("REINSTALL");
|
WARN("REINSTALL");
|
||||||
this.initPrefs();
|
this.initPrefs();
|
||||||
this.reinstallHook();
|
this.reinstallHook(this.curVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -75,87 +74,11 @@ firetray.VersionChange = {
|
|||||||
firetray.Utils.prefService.setCharPref("installedVersion", firetray.VersionChange.curVersion);
|
firetray.Utils.prefService.setCharPref("installedVersion", firetray.VersionChange.curVersion);
|
||||||
},
|
},
|
||||||
|
|
||||||
installHook: function() {},
|
installHook: function(ver){},
|
||||||
upgradeHook: function() {},
|
upgradeHook: function(ver){},
|
||||||
reinstallHook: function() {}
|
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) {}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
provided by this module */
|
provided by this module */
|
||||||
var EXPORTED_SYMBOLS =
|
var EXPORTED_SYMBOLS =
|
||||||
[ "firetray", "LOG", "WARN", "ERROR", "FIREFOX_ID", "THUNDERBIRD_ID",
|
[ "firetray", "LOG", "WARN", "ERROR", "FIREFOX_ID", "THUNDERBIRD_ID",
|
||||||
"SEAMONKEY_ID", "getType", "isArray", "isEmpty", "strEquals",
|
"SEAMONKEY_ID", "FIRETRAY_ID", "FIRETRAY_SPLASH_PAGE", "getType",
|
||||||
"FT_NOTIFICATION_DISABLED", "FT_NOTIFICATION_UNREAD_MESSAGE_COUNT",
|
"isArray", "isEmpty", "strEquals", "FT_NOTIFICATION_DISABLED",
|
||||||
"FT_NOTIFICATION_NEWMAIL_ICON", "FT_NOTIFICATION_CUSTOM_ICON",
|
"FT_NOTIFICATION_UNREAD_MESSAGE_COUNT", "FT_NOTIFICATION_NEWMAIL_ICON",
|
||||||
|
"FT_NOTIFICATION_CUSTOM_ICON",
|
||||||
"FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
|
"FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
|
||||||
"FIRETRAY_DELAY_NOWAIT_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 SEAMONKEY_ID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}";
|
||||||
const CHATZILLA_ID = "{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}";
|
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_DISABLED = 0;
|
||||||
const FT_NOTIFICATION_UNREAD_MESSAGE_COUNT = 1;
|
const FT_NOTIFICATION_UNREAD_MESSAGE_COUNT = 1;
|
||||||
const FT_NOTIFICATION_NEWMAIL_ICON = 2;
|
const FT_NOTIFICATION_NEWMAIL_ICON = 2;
|
||||||
@ -177,7 +181,6 @@ firetray.Utils = {
|
|||||||
delay, timerType);
|
delay, timerType);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
tryCloseLibs: function(libs) {
|
tryCloseLibs: function(libs) {
|
||||||
try {
|
try {
|
||||||
libs.forEach(function(lib) {
|
libs.forEach(function(lib) {
|
||||||
|
Loading…
Reference in New Issue
Block a user