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>
pull/3909/head
Michael Telatynski 2017-05-17 10:39:43 +01:00
parent 826a571b60
commit 9352e5d78e
3 changed files with 38 additions and 18 deletions

View File

@ -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) => {

View File

@ -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) {

View File

@ -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 {