From 97353ead0f20b7afd9182437684ef4d4c9027642 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Sun, 20 Jan 2019 07:47:26 +0500 Subject: [PATCH] Unread icon fix, do not create panel icon on macOS ATM. --- main.js | 45 ++++++++++++++++++++++++++++----------------- package.json | 3 ++- renderer.js | 4 ++-- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/main.js b/main.js index b6134f1..0c5241a 100644 --- a/main.js +++ b/main.js @@ -43,19 +43,22 @@ function createWindow() { mainWindow.setIcon(normalIcon); - // Tray icon. - tray = new Tray(normalIcon); - const contextMenu = Menu.buildFromTemplate([ - { label: 'Open Yandex.Mail window', type: 'normal', click: showHideMainWindow }, - { label: '-', type: 'separator' }, - { label: 'Exit Yandex.Mail wrapper', type: 'normal', click: quitWrapper } - ]); - tray.setTitle('Yandex.Mail'); - tray.setToolTip('Yandex.Mail'); - tray.setContextMenu(contextMenu); - tray.on('click', () => { - showHideMainWindow(null, mainWindow, null); - }); + // Tray icon. Do not create it on macOS. + if (app.platform != "darwin") { + tray = new Tray(normalIcon); + const contextMenu = Menu.buildFromTemplate([ + { label: 'Open Yandex.Mail window', type: 'normal', click: showHideMainWindow }, + { label: '-', type: 'separator' }, + { label: 'Exit Yandex.Mail wrapper', type: 'normal', click: quitWrapper } + ]); + tray.setTitle('Yandex.Mail'); + tray.setToolTip('Yandex.Mail'); + tray.setContextMenu(contextMenu); + tray.on('click', () => { + showHideMainWindow(null, mainWindow, null); + }); + + } mainWindow.Notification = function (title, options) { 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); - 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); - tray.setImage(normalIcon); + if (app.platform == "darwin") { + app.setBadgeCount(count); + } else { + tray.setImage(unreadIcon); + } }) function showHideMainWindow() { diff --git a/package.json b/package.json index b7638dc..cae725a 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "productName": "Yandex.Mail Desktop", "copyright": "Copyright (c) 2019, Stanislav N. aka pztrn", "mac": { - "category": "name.pztrn.yandexmail-desktop" + "category": "name.pztrn.yandexmail-desktop", + "icon": "./assets/icons/icon.png" }, "linux": { "category": "Internet", diff --git a/renderer.js b/renderer.js index 71fd712..59cbc6d 100644 --- a/renderer.js +++ b/renderer.js @@ -3,8 +3,8 @@ var ipc = require("electron").ipcRenderer; function checkForUnreads() { unread = parseInt(document.title.split(" ")[0]); - if (unread > 0) { - ipc.send('has-unread'); + if (typeof (unread) != NaN && unread > 0) { + ipc.send('has-unread', unread); } else { ipc.send('has-no-unread'); };