From 9352e5d78ea1b003ec74939d4299106f2fa4103b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 17 May 2017 10:39:43 +0100 Subject: [PATCH] Lets make it abundantly clear that we want attention. FLASH FLASH FLASH also improve favicon updating to not change if we're same as previous not sure how intensive the nativeImage stuff is but cheap efficiency For FLASH FLASH I moved the setBadgeCount stuff RPC -> IPC should be more reliable now, its in electron-main Win only: if mainWindow is set and is not in focus make it FLASH clear flash if notification gets cleared elsewhere debounce focus handler so we don't set a million of them if the app is backgrounded a while Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/src/electron-main.js | 21 ++++++++++++++++++++- electron_app/src/tray.js | 21 +++++++++++++++------ src/vector/platform/ElectronPlatform.js | 14 +++----------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index 32e305d8d9..b632708f86 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -155,12 +155,31 @@ function startAutoUpdate(update_base_url) { // no other way to catch this error). // Assuming we generally run from the console when developing, // this is far preferable. -process.on('uncaughtException', function (error) { +process.on('uncaughtException', function(error) { console.log("Unhandled exception", error); }); electron.ipcMain.on('install_update', installUpdate); +let focusHandlerAttached = false; +electron.ipcMain.on('setBadgeCount', function(ev, count) { + electron.app.setBadgeCount(count); + if (process.platform === 'win32' && mainWindow && !mainWindow.isFocused()) { + if (count > 0) { + if (!focusHandlerAttached) { + mainWindow.once('focus', () => { + mainWindow.flashFrame(false); + focusHandlerAttached = false; + }); + focusHandlerAttached = true; + } + mainWindow.flashFrame(true); + } else { + mainWindow.flashFrame(false); + } + } +}); + electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing'); const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => { diff --git a/electron_app/src/tray.js b/electron_app/src/tray.js index 98ffb9f40e..5409194d8f 100644 --- a/electron_app/src/tray.js +++ b/electron_app/src/tray.js @@ -60,15 +60,24 @@ exports.create = function(win, config) { trayIcon.setContextMenu(contextMenu); trayIcon.on('click', toggleWin); + let lastFavicon = null; win.webContents.on('page-favicon-updated', function(ev, favicons) { + let newFavicon = config.icon_path; if (favicons && favicons.length > 0 && favicons[0].startsWith('data:')) { - const image = nativeImage.createFromDataURL(favicons[0]); - trayIcon.setImage(image); - win.setIcon(image); - } else { - trayIcon.setImage(config.icon_path); - win.setIcon(config.icon_path); + newFavicon = favicons[0]; } + + // No need to change, shortcut + if (newFavicon === lastFavicon) return; + lastFavicon = newFavicon; + + // if its not default we have to construct into nativeImage + if (newFavicon !== config.icon_path) { + newFavicon = nativeImage.createFromDataURL(favicons[0]); + } + + trayIcon.setImage(newFavicon); + win.setIcon(newFavicon); }); win.webContents.on('page-title-updated', function(ev, title) { diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index 82ef0b5168..5710e66e4a 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -20,7 +20,7 @@ limitations under the License. import VectorBasePlatform from './VectorBasePlatform'; import dis from 'matrix-react-sdk/lib/dispatcher'; import q from 'q'; -import electron, {remote} from 'electron'; +import electron, {remote, ipcRenderer} from 'electron'; remote.autoUpdater.on('update-downloaded', onUpdateDownloaded); @@ -58,16 +58,8 @@ export default class ElectronPlatform extends VectorBasePlatform { setNotificationCount(count: number) { if (this.notificationCount === count) return; super.setNotificationCount(count); - // this sometimes throws because electron is made of fail: - // https://github.com/electron/electron/issues/7351 - // For now, let's catch the error, but I suspect it may - // continue to fail and we might just have to accept that - // electron's remote RPC is a non-starter for now and use IPC - try { - remote.app.setBadgeCount(count); - } catch (e) { - console.error('Failed to set notification count', e); - } + + ipcRenderer.send('setBadgeCount', count); } supportsNotifications(): boolean {