* refactor appinfo initializations

* fix icon tooltip when unread messages
This commit is contained in:
foudfou 2012-03-09 13:27:49 +01:00
parent 98cfa3eee1
commit b6b8d5dca0
4 changed files with 22 additions and 33 deletions

View File

@ -35,12 +35,12 @@ firetray.Handler = {
FILENAME_NEWMAIL: null,
initialized: false,
appNameOriginal: null,
appStarted: false,
appName: null,
runtimeOS: null,
appName: (function(){return Services.appinfo.name;})(),
runtimeABI: (function(){return Services.appinfo.XPCOMABI;})(),
runtimeOS: (function(){return Services.appinfo.OS;})(), // "WINNT", "Linux", "Darwin"
inMailApp: false,
inBrowserApp: false,
appStarted: false,
windows: {},
windowsCount: 0,
visibleWindowsCount: 0,
@ -48,16 +48,6 @@ firetray.Handler = {
init: function() { // does creates icon
firetray.PrefListener.register(false);
this.appNameOriginal = Services.appinfo.name;
this.FILENAME_DEFAULT = firetray.Utils.chromeToPath(
"chrome://firetray/skin/" + this.appNameOriginal.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");
this.runtimeABI = Services.appinfo.XPCOMABI;
this.runtimeOS = Services.appinfo.OS; // "WINNT", "Linux", "Darwin"
// version checked during install, so we shouldn't need to care
let xulVer = Services.appinfo.platformVersion; // Services.vc.compare(xulVer,"2.0a")>=0
firetray.LOG("OS=" + this.runtimeOS + ", ABI=" + this.runtimeABI + ", XULrunner=" + xulVer);
@ -73,13 +63,19 @@ firetray.Handler = {
return false;
}
this.appName = Services.appinfo.name;
if (this.appName === "Thunderbird" || this.appName === "SeaMonkey")
this.inMailApp = true;
if (this.appName === "Firefox" || this.appName === "SeaMonkey")
this.inBrowserApp = true;
firetray.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");
firetray.StatusIcon.init();
firetray.Handler.showHideIcon();
firetray.LOG('StatusIcon initialized');

View File

@ -109,23 +109,23 @@ firetray.Messaging = {
if (!this.initialized)
return;
// initialize
let newMsgCount, localizedTooltip;
let msgCountType = firetray.Utils.prefService.getIntPref("message_count_type");
firetray.LOG("msgCountType="+msgCountType);
let folderCountFunction, localizedTooltip;
if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD) {
folderCountFunction = this.unreadMsgCountIterate;
newMsgCount = this.countMessages(this.unreadMsgCountIterate);
localizedTooltip = PluralForm.get(
newMsgCount,
firetray.Utils.strings.GetStringFromName("tooltip.unread_messages"))
.replace("#1", newMsgCount);;
.replace("#1", newMsgCount);
firetray.WARN(localizedTooltip);
} else if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW) {
folderCountFunction = this.newMsgCountIterate;
newMsgCount = this.countMessages(this.newMsgCountIterate);
localizedTooltip = firetray.Utils.strings.GetStringFromName("tooltip.new_messages");
} else
firetray.ERROR('unknown message count type');
let newMsgCount = this.countMessages(folderCountFunction);
// update icon
if (newMsgCount == 0) {
firetray.Handler.setIconImageDefault();
@ -149,13 +149,6 @@ firetray.Messaging = {
firetray.ERROR("Unknown notification mode: "+prefMailNotification);
}
if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD) {
folderCountFunction = this.unreadMsgCountIterate;
} else if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW) {
folderCountFunction = this.newMsgCountIterate;
} else
firetray.ERROR('unknown message count type');
firetray.Handler.setIconTooltip(localizedTooltip);
} else {

View File

@ -143,9 +143,9 @@ firetray.Handler.setIconTooltip = function(toolTipStr) {
};
firetray.Handler.setIconTooltipDefault = function() {
if (!this.appNameOriginal)
if (!this.appName)
throw "application name not initialized";
this.setIconTooltip(this.appNameOriginal);
this.setIconTooltip(this.appName);
};
firetray.Handler.setIconText = function(text, color) { // FIXME: function too long

View File

@ -455,10 +455,10 @@ firetray.Window = {
getWindowTitle: function(xid) {
let title = firetray.Handler.windows[xid].baseWin.title;
firetray.LOG("baseWin.title="+title);
let tailIndex = title.indexOf(" - Mozilla "+firetray.Handler.appNameOriginal);
let tailIndex = title.indexOf(" - Mozilla "+firetray.Handler.appName);
if (tailIndex !== -1)
return title.substring(0, tailIndex);
else if (title === "Mozilla "+firetray.Handler.appNameOriginal)
else if (title === "Mozilla "+firetray.Handler.appName)
return title;
else
return null;
@ -531,7 +531,7 @@ firetray.Handler.registerWindow = function(win) {
if (x.name === "RangeError") // instanceof not working :-(
win.alert(x+"\n\nYou seem to have more than "+FIRETRAY_WINDOW_COUNT_MAX
+" windows open. This breaks FireTray and most probably "
+firetray.Handler.appNameOriginal+".");
+firetray.Handler.appName+".");
}
this.windowsCount += 1;
// NOTE: no need to check for window state to set visibility because all