Unread icon fix, do not create panel icon on macOS ATM.

This commit is contained in:
Stanislav Nikitin 2019-01-20 07:47:26 +05:00
parent f1ed198d59
commit 97353ead0f
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
3 changed files with 32 additions and 20 deletions

45
main.js
View File

@ -43,19 +43,22 @@ function createWindow() {
mainWindow.setIcon(normalIcon); mainWindow.setIcon(normalIcon);
// Tray icon. // Tray icon. Do not create it on macOS.
tray = new Tray(normalIcon); if (app.platform != "darwin") {
const contextMenu = Menu.buildFromTemplate([ tray = new Tray(normalIcon);
{ label: 'Open Yandex.Mail window', type: 'normal', click: showHideMainWindow }, const contextMenu = Menu.buildFromTemplate([
{ label: '-', type: 'separator' }, { label: 'Open Yandex.Mail window', type: 'normal', click: showHideMainWindow },
{ label: 'Exit Yandex.Mail wrapper', type: 'normal', click: quitWrapper } { label: '-', type: 'separator' },
]); { label: 'Exit Yandex.Mail wrapper', type: 'normal', click: quitWrapper }
tray.setTitle('Yandex.Mail'); ]);
tray.setToolTip('Yandex.Mail'); tray.setTitle('Yandex.Mail');
tray.setContextMenu(contextMenu); tray.setToolTip('Yandex.Mail');
tray.on('click', () => { tray.setContextMenu(contextMenu);
showHideMainWindow(null, mainWindow, null); tray.on('click', () => {
}); showHideMainWindow(null, mainWindow, null);
});
}
mainWindow.Notification = function (title, options) { mainWindow.Notification = function (title, options) {
options.icon = unreadIcon; options.icon = unreadIcon;
@ -82,14 +85,22 @@ app.on('activate', function () {
} }
}); });
ipc.on("has-unread", function () { ipc.on("has-unread", function (event, count) {
mainWindow.setIcon(unreadIcon); mainWindow.setIcon(unreadIcon);
tray.setImage(unreadIcon); if (app.platform == "darwin") {
app.setBadgeCount(count);
} else {
tray.setImage(unreadIcon);
}
}); });
ipc.on("has-no-unread", function () { ipc.on("has-no-unread", function (event, count) {
mainWindow.setIcon(normalIcon); mainWindow.setIcon(normalIcon);
tray.setImage(normalIcon); if (app.platform == "darwin") {
app.setBadgeCount(count);
} else {
tray.setImage(unreadIcon);
}
}) })
function showHideMainWindow() { function showHideMainWindow() {

View File

@ -28,7 +28,8 @@
"productName": "Yandex.Mail Desktop", "productName": "Yandex.Mail Desktop",
"copyright": "Copyright (c) 2019, Stanislav N. aka pztrn", "copyright": "Copyright (c) 2019, Stanislav N. aka pztrn",
"mac": { "mac": {
"category": "name.pztrn.yandexmail-desktop" "category": "name.pztrn.yandexmail-desktop",
"icon": "./assets/icons/icon.png"
}, },
"linux": { "linux": {
"category": "Internet", "category": "Internet",

View File

@ -3,8 +3,8 @@ var ipc = require("electron").ipcRenderer;
function checkForUnreads() { function checkForUnreads() {
unread = parseInt(document.title.split(" ")[0]); unread = parseInt(document.title.split(" ")[0]);
if (unread > 0) { if (typeof (unread) != NaN && unread > 0) {
ipc.send('has-unread'); ipc.send('has-unread', unread);
} else { } else {
ipc.send('has-no-unread'); ipc.send('has-no-unread');
}; };