diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index 32e305d8..b632708f 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 98ffb9f4..5409194d 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 82ef0b51..5710e66e 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 {