1
0
mirror of https://github.com/moparisthebest/FireTray synced 2025-01-07 19:48:03 -05:00

* fix firetray's chat support policy handling

* implement windowGetAttention(), setIconImageDefault(), setIconImageNewMail()

At this stage, we must consider adapting the preferences' UI.
This commit is contained in:
foudfou 2014-02-08 22:41:47 +01:00
parent 70a362a9e4
commit a10b63a8b2
6 changed files with 105 additions and 19 deletions

View File

@ -113,7 +113,7 @@ firetray.Handler = {
let chatIsProvided = this.isChatProvided();
log.info('isChatProvided='+chatIsProvided);
if (chatIsProvided) {
if (FIRETRAY_CHAT_SUPPORTED_OS.indexOf(this.runtimeOS) > -1) {
if (this.isChatSupported()) {
Cu.import("resource://firetray/FiretrayMessaging.jsm"); // needed for existsChatAccount
Cu.import("resource://firetray/"+this.runtimeOS+"/FiretrayChat.jsm");
firetray.Utils.addObservers(firetray.Handler, [
@ -163,7 +163,8 @@ firetray.Handler = {
shutdown: function() {
log.debug("Disabling Handler");
if (firetray.Handler.isChatProvided() && firetray.Chat.initialized)
if (firetray.Handler.isChatProvided() && firetray.Handler.isChatSupported()
&& firetray.Chat.initialized)
firetray.Chat.shutdown();
if (this.inMailApp)
@ -191,6 +192,10 @@ firetray.Handler = {
return this.appHasChat && Services.prefs.getBoolPref("mail.chat.enabled");
},
isChatSupported: function() {
return FIRETRAY_CHAT_SUPPORTED_OS.indexOf(this.runtimeOS) > -1;
},
tryCloseLibs: function() {
try {
for (let libName in this.ctypesLibs) {
@ -332,6 +337,7 @@ firetray.Handler = {
showWindow: function(winId) {},
activateLastWindowCb: function(gtkStatusIcon, gdkEvent, userData) {},
getActiveWindow: function() {},
windowGetAttention: function(winId) {},
showAllWindows: function() {
log.debug("showAllWindows");
@ -565,7 +571,7 @@ firetray.MailChatPrefListener = new PrefListener(
let enableChatCond =
(firetray.Handler.appHasChat &&
firetray.Utils.prefService.getBoolPref("chat_icon_enable") &&
FIRETRAY_CHAT_SUPPORTED_OS.indexOf(this.runtimeOS) > -1);
firetray.Handler.isChatSupported());
if (!enableChatCond) return;
if (Services.prefs.getBoolPref("mail.chat.enabled")) {

View File

@ -183,10 +183,10 @@ firetray.Messaging = {
if (mailChangeTriggerFile)
firetray.Messaging.runProcess(mailChangeTriggerFile, [newMsgCount.toString()]);
let setUrgency = firetray.Utils.prefService.getBoolPref("mail_urgency_hint");
if (setUrgency && (newMsgCount > currentMsgCount))
let getAttention = firetray.Utils.prefService.getBoolPref("mail_urgency_hint"); // FIXME: rename!
if (getAttention && (newMsgCount > currentMsgCount))
for (let winId in firetray.Handler.windows)
firetray.Window.setUrgency(winId, true);
firetray.Handler.windowGetAttention(winId);
}
};

View File

@ -218,6 +218,29 @@ function user32_defines(lib) {
lib.lazy_bind("GetWindowThreadProcessId", win32.DWORD, win32.HWND, win32.LPDWORD);
this.FLASHWINFO = ctypes.StructType("FLASHWINFO", [
{ "cbSize": win32.UINT },
{ "hwnd": win32.HWND },
{ "dwFlags": win32.DWORD },
{ "uCount": win32.UINT },
{ "dwTimeout": win32.DWORD }
]);
this.PFLASHWINFO = this.FLASHWINFO.ptr;
lib.lazy_bind("FlashWindow", win32.BOOL, win32.HWND, win32.BOOL);
lib.lazy_bind("FlashWindowEx", win32.BOOL, this.PFLASHWINFO);
this.FLASHW_STOP = 0;
this.FLASHW_CAPTION = 0x00000001;
this.FLASHW_TRAY = 0x00000002;
this.FLASHW_ALL =(this.FLASHW_CAPTION | this.FLASHW_TRAY);
this.FLASHW_TIMER = 0x00000004;
this.FLASHW_TIMERNOFG = 0x0000000C;
lib.lazy_bind("SystemParametersInfoW", win32.BOOL, win32.UINT, win32.UINT, win32.PVOID, win32.UINT);
this.SPI_GETFOREGROUNDFLASHCOUNT = 0x2004;
lib.lazy_bind("GetForegroundWindow", win32.HWND);
}
new ctypes_library(USER32_LIBNAME, USER32_ABIS, user32_defines, this);

View File

@ -736,6 +736,10 @@ firetray.Handler.getActiveWindow = function() {
return activeWin;
};
firetray.Handler.windowGetAttention = function(winId) {
firetray.Window.setUrgency(winId, true);
};
/**
* init X11 Display and handled XAtoms.

View File

@ -36,14 +36,13 @@ firetray.StatusIcon = {
notifyIconData: null,
hwndProxy: null,
icons: null,
iconsPaths: {},
WNDCLASS_NAME: "FireTrayHiddenWindowClass",
WNDCLASS_ATOM: null,
init: function() {
this.loadIcons();
// this.defineIconNames(); // FIXME: linux-only
this.create();
firetray.Handler.setIconImageNewMail(); // TESTING
this.initialized = true;
return true;
@ -56,16 +55,37 @@ firetray.StatusIcon = {
this.destroyIcons();
this.initialized = false;
return true;
},
defineIconNames: function() { // FIXME: linux-only
this.prefAppIconNames = (function() {
if (firetray.Handler.inMailApp) {
return "app_mail_icon_names";
} else if (firetray.Handler.inBrowserApp) {
return "app_browser_icon_names";
} else {
return "app_default_icon_names";
}
})();
this.defaultAppIconName = firetray.Handler.appName.toLowerCase();
this.prefNewMailIconNames = "new_mail_icon_names";
this.defaultNewMailIconName = "mail-unread";
},
loadIcons: function() {
this.icons = new ctypesMap(win32.HICON);
// the Mozilla hidden window has the default Mozilla icon
let hwnd_hidden_moz = user32.FindWindowW("MozillaHiddenWindowClass", null);
log.debug("=== hwnd_hidden_moz="+hwnd_hidden_moz);
this.icons.insert('app', this.getIconFromWindow(hwnd_hidden_moz));
/* we'll take the first icon in the .ico file. To get the icon count in the
file, pass ctypes.cast(ctypes.int(-1), win32.UINT); */
for (let ico_name in FIRETRAY_ICON_CHROME_PATHS) {
let path = firetray.Utils.chromeToPath(FIRETRAY_ICON_CHROME_PATHS[ico_name]);
this.iconsPaths[ico_name] = path;
let hicon = shell32.ExtractIconW(null, path, 0);
// ERROR_INVALID_HANDLE(6) ignored (_Reserved_ HINSTANCE hInst ?)
this.icons.insert(ico_name, hicon);
@ -76,6 +96,11 @@ firetray.StatusIcon = {
destroyIcons: function() {
let success = true, errors = [];
let keys = this.icons.keys;
// 'app' must not get DestroyIcon'd
var idx_app = keys.indexOf('app');
if (idx_app > -1) keys.splice(idx_app, 1);
for (let i=0, len=keys.length; i<len; ++i) {
let ico_name = keys[i];
let res = user32.DestroyIcon(this.icons.get(ico_name));
@ -85,6 +110,8 @@ firetray.StatusIcon = {
errors.push(ctypes.winLastError);
success = success && res;
}
this.icons.remove('app');
if (!success) {
log.error("Couldn't destroy all icons: "+errors);
} else {
@ -95,15 +122,11 @@ firetray.StatusIcon = {
create: function() {
let hwnd_hidden = this.createProxyWindow();
// the Mozilla hidden window has the default Mozilla icon
let hwnd_hidden_moz = user32.FindWindowW("MozillaHiddenWindowClass", null);
log.debug("=== hwnd_hidden_moz="+hwnd_hidden_moz);
nid = new shell32.NOTIFYICONDATAW();
nid.cbSize = shell32.NOTIFYICONDATAW_SIZE();
log.debug("SIZE="+nid.cbSize);
nid.szTip = firetray.Handler.appName;
nid.hIcon = this.getIconFromWindow(hwnd_hidden_moz);
nid.hIcon = this.icons.get('app');
nid.hWnd = hwnd_hidden;
nid.uCallbackMessage = firetray.Win32.WM_TRAYMESSAGE;
nid.uFlags = shell32.NIF_ICON | shell32.NIF_MESSAGE | shell32.NIF_TIP;
@ -167,6 +190,7 @@ firetray.StatusIcon = {
break;
case win32.WM_RBUTTONUP:
log.debug("WM_RBUTTONUP");
firetray.Handler.windowGetAttention(); // TESTING
break;
case win32.WM_CONTEXTMENU:
log.debug("WM_CONTEXTMENU");
@ -221,19 +245,24 @@ firetray.StatusIcon = {
let rv = shell32.Shell_NotifyIconW(shell32.NIM_DELETE, this.notifyIconData.address());
log.debug("Shell_NotifyIcon DELETE="+rv+" winLastError="+ctypes.winLastError);
this.destroyProxyWindow();
},
setImageFromIcon: function(icoName) {
let nid = firetray.StatusIcon.notifyIconData;
nid.hIcon = firetray.StatusIcon.icons.get(icoName);
rv = shell32.Shell_NotifyIconW(shell32.NIM_MODIFY, nid.address());
log.debug("Shell_NotifyIcon MODIFY="+rv+" winLastError="+ctypes.winLastError);
}
}; // firetray.StatusIcon
firetray.Handler.setIconImageDefault = function() {
log.debug("setIconImageDefault");
firetray.StatusIcon.setImageFromIcon('app');
};
firetray.Handler.setIconImageNewMail = function() {
let nid = firetray.StatusIcon.notifyIconData;
nid.hIcon = firetray.StatusIcon.icons.get('mail-unread');
rv = shell32.Shell_NotifyIconW(shell32.NIM_MODIFY, nid.address());
log.debug("Shell_NotifyIcon MODIFY="+rv+" winLastError="+ctypes.winLastError);
firetray.StatusIcon.setImageFromIcon('mail-unread');
};
// firetray.Handler.setIconImageFromFile = firetray.StatusIcon.setIconImageFromFile;
@ -244,7 +273,7 @@ firetray.Handler.setIconTooltip = function(toolTipStr) {
firetray.Handler.setIconTooltipDefault = function() {
};
firetray.Handler.setIconText = function(text, color) { // FIXME: function too long
firetray.Handler.setIconText = function(text, color) {
};
firetray.Handler.setIconVisibility = function(visible) {

View File

@ -183,3 +183,27 @@ firetray.Handler.showWindow = function(wid) {
firetray.Handler.hideWindow = function(wid) {
return firetray.Window.setVisibility(wid, false);
};
firetray.Handler.windowGetAttention = function(wid) { // see nsWindow.cpp
for (var first in this.windows) break;
wid = wid || first;
let hwnd = firetray.Win32.hexStrToHwnd(wid);
let fgWnd = user32.GetForegroundWindow();
log.debug(hwnd+" === "+fgWnd);
if (firetray.js.strEquals(hwnd, fgWnd) ||
!this.windows[wid].visible)
return;
let defaultCycleCount = new win32.DWORD;
user32.SystemParametersInfoW(user32.SPI_GETFOREGROUNDFLASHCOUNT, 0,
defaultCycleCount.address(), 0);
log.debug("defaultCycleCount="+defaultCycleCount);
let flashInfo = new user32.FLASHWINFO;
flashInfo.cbSize = user32.FLASHWINFO.size;
flashInfo.hwnd = hwnd;
flashInfo.dwFlags = user32.FLASHW_ALL;
flashInfo.uCount = defaultCycleCount;
flashInfo.dwTimeout = 0;
user32.FlashWindowEx(flashInfo.address());
};