Skip to content

Commit

Permalink
tray icon implementation for Windows OS (compatibility fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
inbasic committed Feb 16, 2014
1 parent 8fa478b commit e1151fa
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
Binary file modified drawings/new-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/data/toolbar-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/gmail-notifier.xpi
Binary file not shown.
41 changes: 27 additions & 14 deletions src/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ var tabs = require("sdk/tabs"),
return {
set: function () {},
remove: function () {},
callback: function () {}
callback: {
install: function () {},
remove: function () {}
}
};
})();

Expand Down Expand Up @@ -84,9 +87,9 @@ var config = {
};

/** tray callback handling **/
tray.callback(function () {
windows.active.focus();
onCommand();
tray.callback.install(function () {
console.error(windows.active.focus);
timer.setTimeout(onCommand, 100);
});
/** libraries **/
Cu.import("resource://gre/modules/Promise.jsm");
Expand Down Expand Up @@ -242,7 +245,7 @@ contextPanel.port.on("clipboard", (function () {
.getService(Ci.nsIClipboardHelper);
return function (str) {
gClipboardHelper.copyString(str);
notify(_("gmail"), _("msg13"), true);
notify(_("gmail"), _("msg13"));
}
})());

Expand Down Expand Up @@ -425,13 +428,14 @@ exports.main = function(options, callbacks) {
var aWindow = windows.active;
var aftercustomizationListener = function () {
let button = aWindow.document.getElementById(config.toolbar.id);
if (!button) return;
if (!button || !button.nextSibling) return;
prefs.nextSibling = button.nextSibling.id;
}
aWindow.addEventListener("aftercustomization", aftercustomizationListener, false);
exports.onUnload = function (reason) {
aWindow.removeEventListener("aftercustomization", aftercustomizationListener, false);
tray.remove();
tray.callback.remove();
}

/** Prefs Listener**/
Expand Down Expand Up @@ -669,7 +673,6 @@ function Server () {
color = "load";
}
Promise.all(emails.map(e => e())).then(function (objs) {
console.error(objs);
var isAuthorized = objs.reduce((p, c) => p || (!c.notAuthorized && c.network), false);
var anyNewEmails = objs.reduce((p, c) => p || (c.newIDs.length !== 0), false);
if (!isAuthorized) {
Expand All @@ -684,7 +687,7 @@ function Server () {
}
tray.remove();
gButton.tooltiptext = config.defaultTooltip;
console.error("exit 4");
console.error(objs, "exit 4");
return;
}
//Removing not logged-in accounts
Expand All @@ -701,7 +704,7 @@ console.error("exit 4");
var newCount = objs.reduce((p,c) => p + c.xml.fullcount, 0);
//
if (!anyNewEmails && !forced && count === newCount) {
console.error("exit 0");
console.error(objs, "exit 0", forced, anyNewEmails);
return; //Everything is clear
}
count = newCount;
Expand Down Expand Up @@ -737,7 +740,7 @@ console.error("exit 0");
p += c.xml.title +
(c.xml.label ? " [" + c.xml.label + "]" : "") +
" (" + c.xml.fullcount + ")" + "\n", ""
);
).replace(/\n$/, "");
if (!forced && !anyNewEmails) {
if (newCount) {
icon(newCount, "red"); color = "red";
Expand All @@ -749,13 +752,13 @@ console.error("exit 0");
tray.remove();
gButton.tooltiptext = tooltip;
}
console.error("exit 1");
console.error(objs, "exit 1", forced, anyNewEmails);
}
else if (forced && !anyNewEmails) {
else if (forced && !newCount) {
icon(null, "gray"); color = "gray";
tray.remove();
gButton.tooltiptext = tooltip;
console.error("exit 3");
console.error(objs, "exit 3", forced, anyNewEmails);
}
else {
icon(newCount, "new"); color = "new";
Expand All @@ -766,7 +769,7 @@ console.error("exit 3");
if (prefs.alert) play();
gButton.tooltiptext = tooltip;

console.error("exit 2");
console.error(objs, "exit 2", forced, anyNewEmails);
}
//Updating the toolbar panel if exists
if (contextPanel.isShowing) {
Expand Down Expand Up @@ -806,7 +809,17 @@ sp.on("reset", function() {
prefs.currentTab = false;
prefs.doReadOnArchive = true;
prefs.soundVolume = 80;
prefs.tray = true;
prefs.notificationFormat = "From: [author_email][break]Title: [title][break]Summary: [summary]";
});
sp.on("tray", function() {
if (!prefs.tray) {
tray.remove();
}
else {
tm.reset(true);
}
})

/**
* Send archive, mark as read, mark as unread, and trash commands to Gmail server
Expand Down
18 changes: 12 additions & 6 deletions src/lib/tray/winnt/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Cu.import("resource://gre/modules/Promise.jsm");

var config = {
id: {
msg: 336518, // A random number
msg: 665, // A random number
unique: 24342 // A random number
},
time: {
Expand Down Expand Up @@ -190,8 +190,7 @@ var proxyWndProc = WNDPROC (function (hWnd, uMsg, wParam, lParam) {
}
return user32.DefWindowProcW(hWnd, uMsg, wParam, lParam);
})
user32.SetWindowLongW(hWnd, -4 /* GWLP_WNDPROC */, ctypes.cast(proxyWndProc, LONG_PTR));

var oldOffset = user32.SetWindowLongW(hWnd, -4 /* GWLP_WNDPROC */, ctypes.cast(proxyWndProc, LONG_PTR));

var isInstalled = false;
exports.set = function (badge, msg) {
Expand All @@ -212,6 +211,13 @@ exports.remove = function () {
shell32.Shell_NotifyIconW(0x00000002 /* NIM_DELETE */, nid.address());
isInstalled = false;
}
exports.callback = function (c) {
callback = c;
}
exports.callback = {
install: function (c) {
callback = c;
},
remove: function () {
console.error(0, oldOffset.toSource())
user32.SetWindowLongW(hWnd, -4, oldOffset);
}
}

4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contributors": ["CaTz", "ecaron"],

"url": "",
"version": "0.3.8b2",
"version": "0.4.0b1",
"lib": "lib",
"main": "main",

Expand Down Expand Up @@ -72,7 +72,7 @@
},
{
"name": "tray",
"title": "Display Windows taskbar notification:",
"title": "Display Windows taskbar notification (beta):",
"description": "Taskbar notifications are only supported in Windows OS at the moment.",
"type": "bool",
"value": true
Expand Down
4 changes: 2 additions & 2 deletions template/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>14.0</em:minVersion>
<em:maxVersion>28.0</em:maxVersion>
<em:minVersion>27.0</em:minVersion>
<em:maxVersion>30.0</em:maxVersion>
</Description>
</em:targetApplication>

Expand Down

0 comments on commit e1151fa

Please sign in to comment.