From da3e283e234aa89ce1b51258c84d9704be96bb22 Mon Sep 17 00:00:00 2001 From: TheGoddessInari Date: Mon, 18 Feb 2019 15:28:06 -0800 Subject: [PATCH] Redo icon handling with NativeImages to prevent random error boxes. --- app.json | 5 ++++- electron/main.js | 4 ++-- electron/tray.js | 25 ++++++++++++------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app.json b/app.json index f203636e..c9152974 100644 --- a/app.json +++ b/app.json @@ -273,7 +273,10 @@ "app.js", "resources/Rambox-all.css", "resources/Icon.png", - "resources/Icon.ico" + "resources/Icon.ico", + "resources/IconTray.png", + "resources/IconTrayUnread.png", + "resources/IconTrayUnread.ico" ], /** * List of items in the NETWORK section diff --git a/electron/main.js b/electron/main.js index 93bd9941..476dd8f4 100644 --- a/electron/main.js +++ b/electron/main.js @@ -80,7 +80,7 @@ function createWindow () { // Create the browser window using the state information mainWindow = new BrowserWindow({ title: 'Rambox-OS' - ,icon: path.join(app.getAppPath(), '/resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico')) + ,icon: nativeImage.createFromPath(path.join(app.getAppPath(), '/resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico'))) ,backgroundColor: '#FFF' ,x: config.get('x') ,y: config.get('y') @@ -375,7 +375,7 @@ ipcMain.on('image:popup', function(event, url, partition) { width: mainWindow.getBounds().width ,height: mainWindow.getBounds().height ,parent: mainWindow - ,icon: path.join(app.getAppPath(), '/resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico')) + ,icon: nativeImage.createFromPath(path.join(app.getAppPath(), '/resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico'))) ,backgroundColor: '#FFF' ,autoHideMenuBar: true ,skipTaskbar: true diff --git a/electron/tray.js b/electron/tray.js index 5eed76bc..83f1da77 100644 --- a/electron/tray.js +++ b/electron/tray.js @@ -1,20 +1,18 @@ const path = require('path'); -const electron = require('electron'); -const app = electron.app; +const {app, electron, nativeImage, Menu, MenuItem, Tray} = require('electron'); // Module to create tray icon -const Tray = electron.Tray; -const MenuItem = electron.MenuItem; var appIcon = null; exports.create = function(win, config) { if (process.platform === 'darwin' || appIcon || config.get('window_display_behavior') === 'show_taskbar' ) return; const locale = require(path.join(app.getAppPath(), '/resources/languages/'+config.get('locale'))); - const icon = process.platform === 'linux' || process.platform === 'darwin' ? 'IconTray.png' : 'Icon.ico'; - const iconPath = path.join(app.getAppPath(), `/resources/${icon}`); + const iconName = process.platform === 'linux' || process.platform === 'darwin' ? 'IconTray.png' : 'Icon.ico'; + const iconPath = path.join(app.getAppPath(), `/resources/${iconName}`); + const icon = nativeImage.createFromPath(iconPath); - const contextMenu = electron.Menu.buildFromTemplate([ + const contextMenu = Menu.buildFromTemplate([ { label: locale['tray[0]'], click() { @@ -32,7 +30,7 @@ exports.create = function(win, config) { } ]); - appIcon = new Tray(iconPath); + appIcon = new Tray(icon); appIcon.setToolTip('Rambox-OS'); appIcon.setContextMenu(contextMenu); @@ -66,13 +64,14 @@ exports.destroy = function() { exports.setBadge = function(messageCount, showUnreadTray) { if (process.platform === 'darwin' || !appIcon) return; - let icon; + let iconName; if (process.platform === 'linux') { - icon = messageCount > 0 && showUnreadTray ? 'IconTrayUnread.png' : 'IconTray.png'; + iconName = messageCount > 0 && showUnreadTray ? 'IconTrayUnread.png' : 'IconTray.png'; } else { - icon = messageCount > 0 && showUnreadTray ? 'IconTrayUnread.ico' : 'Icon.ico'; + iconName = messageCount > 0 && showUnreadTray ? 'IconTrayUnread.ico' : 'Icon.ico'; } - const iconPath = path.join(app.getAppPath(), `/resources/${icon}`); - appIcon.setImage(iconPath); + const iconPath = path.join(app.getAppPath(), `/resources/${iconName}`); + const icon = nativeImage.createFromPath(iconPath); + appIcon.setImage(icon); };