diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d1990b6..cbe5f7e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ #### Windows - Added the tooltip for the tray icon in order to show count of unread channels/mantions. +#### OS X +- Added colored badges to the menu icon when there are unread channels/mentions. + #### Linux - Added the option to show the icon on menu bar. (requires libappindicator1 on Ubuntu) diff --git a/resources/osx/ClickedMenuIcon.svg b/resources/osx/ClickedMenuIcon.svg new file mode 100644 index 00000000..36de34c9 --- /dev/null +++ b/resources/osx/ClickedMenuIcon.svg @@ -0,0 +1,58 @@ + +image/svg+xml \ No newline at end of file diff --git a/resources/osx/ClickedMenuIconMention.svg b/resources/osx/ClickedMenuIconMention.svg new file mode 100644 index 00000000..12125217 --- /dev/null +++ b/resources/osx/ClickedMenuIconMention.svg @@ -0,0 +1,69 @@ + +image/svg+xml \ No newline at end of file diff --git a/resources/osx/ClickedMenuIconUnread.svg b/resources/osx/ClickedMenuIconUnread.svg new file mode 100644 index 00000000..bab613cb --- /dev/null +++ b/resources/osx/ClickedMenuIconUnread.svg @@ -0,0 +1,69 @@ + +image/svg+xml \ No newline at end of file diff --git a/resources/osx/MenuIcon.svg b/resources/osx/MenuIcon.svg new file mode 100644 index 00000000..10627108 --- /dev/null +++ b/resources/osx/MenuIcon.svg @@ -0,0 +1,58 @@ + +image/svg+xml \ No newline at end of file diff --git a/resources/osx/MenuIconMention.svg b/resources/osx/MenuIconMention.svg new file mode 100644 index 00000000..6a97864a --- /dev/null +++ b/resources/osx/MenuIconMention.svg @@ -0,0 +1,69 @@ + +image/svg+xml \ No newline at end of file diff --git a/resources/osx/MenuIconMentionTemplate.svg b/resources/osx/MenuIconMentionTemplate.svg deleted file mode 100644 index 2c390b00..00000000 --- a/resources/osx/MenuIconMentionTemplate.svg +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - diff --git a/resources/osx/MenuIconTemplate.png b/resources/osx/MenuIconTemplate.png deleted file mode 100644 index 2e993e9e..00000000 Binary files a/resources/osx/MenuIconTemplate.png and /dev/null differ diff --git a/resources/osx/MenuIconUnread.svg b/resources/osx/MenuIconUnread.svg new file mode 100644 index 00000000..e80d0860 --- /dev/null +++ b/resources/osx/MenuIconUnread.svg @@ -0,0 +1,69 @@ + +image/svg+xml \ No newline at end of file diff --git a/resources/osx/MenuIconUnreadTemplate.svg b/resources/osx/MenuIconUnreadTemplate.svg deleted file mode 100644 index 113578d0..00000000 --- a/resources/osx/MenuIconUnreadTemplate.svg +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - diff --git a/src/main.js b/src/main.js index cd8aa67f..994f1b3b 100644 --- a/src/main.js +++ b/src/main.js @@ -1,15 +1,18 @@ 'use strict'; -const electron = require('electron'); -const app = electron.app; // Module to control application life. +const { + app, + BrowserWindow, + Menu, + Tray, + ipcMain, + nativeImage, + dialog, + systemPreferences +} = require('electron'); if (require('electron-squirrel-startup')) app.quit(); -const BrowserWindow = electron.BrowserWindow; // Module to create native browser window. -const Menu = electron.Menu; -const Tray = electron.Tray; -const ipc = electron.ipcMain; -const nativeImage = electron.nativeImage; const fs = require('fs'); const path = require('path'); @@ -49,6 +52,20 @@ catch (e) { console.log('Failed to read or upgrade config.json'); } +// Only for OS X +const switchMenuIconImages = function(icons, isDarkMode) { + if (isDarkMode) { + icons.normal = icons.clicked.normal; + icons.unread = icons.clicked.unread; + icons.mention = icons.clicked.mention; + } + else { + icons.normal = icons.light.normal; + icons.unread = icons.light.unread; + icons.mention = icons.light.mention; + } +}; + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. var mainWindow = null; @@ -62,11 +79,20 @@ const trayImages = function() { mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_mention.ico')) }; case 'darwin': - return { - normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconTemplate.png')), - unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconUnreadTemplate.png')), - mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconMentionTemplate.png')) + const icons = { + light: { + normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIcon.png')), + unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconUnread.png')), + mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconMention.png')) + }, + clicked: { + normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIcon.png')), + unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconUnread.png')), + mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconMention.png')) + } }; + switchMenuIconImages(icons, systemPreferences.isDarkMode()); + return icons; case 'linux': var resourcesDir = 'resources/linux/' + (config.trayIconTheme || 'light') + '/'; return { @@ -129,7 +155,7 @@ app.on('certificate-error', function(event, webContents, url, error, certificate detail = `Certificate is different from previous one.\n\n` + detail; } - electron.dialog.showMessageBox(mainWindow, { + dialog.showMessageBox(mainWindow, { title: 'Certificate error', message: `Do you trust certificate from "${certificate.issuerName}"?`, detail: detail, @@ -152,7 +178,7 @@ app.on('certificate-error', function(event, webContents, url, error, certificate const loginCallbackMap = new Map(); -ipc.on('login-credentials', function(event, request, user, password) { +ipcMain.on('login-credentials', function(event, request, user, password) { const callback = loginCallbackMap.get(JSON.stringify(request)); if (callback != null) { callback(user, password); @@ -173,6 +199,14 @@ app.on('ready', function() { if (shouldShowTrayIcon()) { // set up tray icon trayIcon = new Tray(trayImages.normal); + if (process.platform === 'darwin') { + trayIcon.setPressedImage(trayImages.clicked.normal); + systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', (event, userInfo) => { + switchMenuIconImages(trayImages, systemPreferences.isDarkMode()); + trayIcon.setImage(trayImages.normal); + }); + } + trayIcon.setToolTip(app.getName()); trayIcon.on('click', function() { mainWindow.focus(); @@ -183,7 +217,7 @@ app.on('ready', function() { trayIcon.on('balloon-click', function() { mainWindow.focus(); }); - ipc.on('notified', function(event, arg) { + ipcMain.on('notified', function(event, arg) { trayIcon.displayBalloon({ icon: path.resolve(__dirname, 'resources/appicon.png'), title: arg.title, @@ -193,22 +227,31 @@ app.on('ready', function() { // Set overlay icon from dataURL // Set trayicon to show "dot" - ipc.on('update-unread', function(event, arg) { + ipcMain.on('update-unread', function(event, arg) { if (process.platform === 'win32') { - const overlay = arg.overlayDataURL ? electron.nativeImage.createFromDataURL(arg.overlayDataURL) : null; + const overlay = arg.overlayDataURL ? nativeImage.createFromDataURL(arg.overlayDataURL) : null; mainWindow.setOverlayIcon(overlay, arg.description); } if (arg.mentionCount > 0) { trayIcon.setImage(trayImages.mention); + if (process.platform === 'darwin') { + trayIcon.setPressedImage(trayImages.clicked.mention); + } trayIcon.setToolTip(arg.mentionCount + ' unread mentions'); } else if (arg.unreadCount > 0) { trayIcon.setImage(trayImages.unread); + if (process.platform === 'darwin') { + trayIcon.setPressedImage(trayImages.clicked.unread); + } trayIcon.setToolTip(arg.unreadCount + ' unread channels'); } else { trayIcon.setImage(trayImages.normal); + if (process.platform === 'darwin') { + trayIcon.setPressedImage(trayImages.clicked.normal); + } trayIcon.setToolTip(app.getName()); } }); @@ -241,11 +284,11 @@ app.on('ready', function() { mainWindow.loadURL('file://' + __dirname + '/browser/index.html'); // Set application menu - ipc.on('update-menu', (event, config) => { + ipcMain.on('update-menu', (event, config) => { var app_menu = appMenu.createMenu(mainWindow, config); Menu.setApplicationMenu(app_menu); }); - ipc.emit('update-menu', true, config); + ipcMain.emit('update-menu', true, config); // set up context menu for tray icon if (shouldShowTrayIcon()) { diff --git a/src/resources/osx/ClickedMenuIcon.png b/src/resources/osx/ClickedMenuIcon.png new file mode 100644 index 00000000..66159dd1 Binary files /dev/null and b/src/resources/osx/ClickedMenuIcon.png differ diff --git a/src/resources/osx/ClickedMenuIcon@2x.png b/src/resources/osx/ClickedMenuIcon@2x.png new file mode 100644 index 00000000..89ca03ed Binary files /dev/null and b/src/resources/osx/ClickedMenuIcon@2x.png differ diff --git a/src/resources/osx/ClickedMenuIconMention.png b/src/resources/osx/ClickedMenuIconMention.png new file mode 100644 index 00000000..253d81dd Binary files /dev/null and b/src/resources/osx/ClickedMenuIconMention.png differ diff --git a/src/resources/osx/ClickedMenuIconMention@2x.png b/src/resources/osx/ClickedMenuIconMention@2x.png new file mode 100644 index 00000000..668cbcac Binary files /dev/null and b/src/resources/osx/ClickedMenuIconMention@2x.png differ diff --git a/src/resources/osx/ClickedMenuIconUnread.png b/src/resources/osx/ClickedMenuIconUnread.png new file mode 100644 index 00000000..b223b242 Binary files /dev/null and b/src/resources/osx/ClickedMenuIconUnread.png differ diff --git a/src/resources/osx/ClickedMenuIconUnread@2x.png b/src/resources/osx/ClickedMenuIconUnread@2x.png new file mode 100644 index 00000000..8ec0256b Binary files /dev/null and b/src/resources/osx/ClickedMenuIconUnread@2x.png differ diff --git a/src/resources/osx/MenuIcon.png b/src/resources/osx/MenuIcon.png new file mode 100644 index 00000000..e40d350f Binary files /dev/null and b/src/resources/osx/MenuIcon.png differ diff --git a/src/resources/osx/MenuIcon@2x.png b/src/resources/osx/MenuIcon@2x.png new file mode 100644 index 00000000..deb0d47f Binary files /dev/null and b/src/resources/osx/MenuIcon@2x.png differ diff --git a/src/resources/osx/MenuIconMention.png b/src/resources/osx/MenuIconMention.png new file mode 100644 index 00000000..73d8f73b Binary files /dev/null and b/src/resources/osx/MenuIconMention.png differ diff --git a/src/resources/osx/MenuIconMention@2x.png b/src/resources/osx/MenuIconMention@2x.png new file mode 100644 index 00000000..4ffe1a15 Binary files /dev/null and b/src/resources/osx/MenuIconMention@2x.png differ diff --git a/src/resources/osx/MenuIconMentionTemplate.png b/src/resources/osx/MenuIconMentionTemplate.png deleted file mode 100644 index 0536f189..00000000 Binary files a/src/resources/osx/MenuIconMentionTemplate.png and /dev/null differ diff --git a/src/resources/osx/MenuIconMentionTemplate@2x.png b/src/resources/osx/MenuIconMentionTemplate@2x.png deleted file mode 100644 index 0f1a6134..00000000 Binary files a/src/resources/osx/MenuIconMentionTemplate@2x.png and /dev/null differ diff --git a/src/resources/osx/MenuIconTemplate.png b/src/resources/osx/MenuIconTemplate.png deleted file mode 100644 index 9c675b3c..00000000 Binary files a/src/resources/osx/MenuIconTemplate.png and /dev/null differ diff --git a/src/resources/osx/MenuIconTemplate@2x.png b/src/resources/osx/MenuIconTemplate@2x.png deleted file mode 100644 index 31e065d8..00000000 Binary files a/src/resources/osx/MenuIconTemplate@2x.png and /dev/null differ diff --git a/src/resources/osx/MenuIconUnread.png b/src/resources/osx/MenuIconUnread.png new file mode 100644 index 00000000..fee97024 Binary files /dev/null and b/src/resources/osx/MenuIconUnread.png differ diff --git a/src/resources/osx/MenuIconUnread@2x.png b/src/resources/osx/MenuIconUnread@2x.png new file mode 100644 index 00000000..33d1a5bb Binary files /dev/null and b/src/resources/osx/MenuIconUnread@2x.png differ diff --git a/src/resources/osx/MenuIconUnreadTemplate.png b/src/resources/osx/MenuIconUnreadTemplate.png deleted file mode 100644 index 5c1eff26..00000000 Binary files a/src/resources/osx/MenuIconUnreadTemplate.png and /dev/null differ diff --git a/src/resources/osx/MenuIconUnreadTemplate@2x.png b/src/resources/osx/MenuIconUnreadTemplate@2x.png deleted file mode 100644 index a6f2811a..00000000 Binary files a/src/resources/osx/MenuIconUnreadTemplate@2x.png and /dev/null differ