Refactor notification to simplify event handling

This commit is contained in:
Yuya Ochiai 2016-06-16 22:10:55 +09:00
parent 73a11ea398
commit 722807a5cb
3 changed files with 40 additions and 45 deletions

View file

@ -97,30 +97,15 @@ function isElementVisible(elem) {
return elem.offsetHeight !== 0; return elem.offsetHeight !== 0;
} }
// On Windows 8.1 and Windows 8, a shortcut with a Application User Model ID must be installed to the Start screen.
// In current version, use tray balloon for notification
function isLowerThanOrEqualWindows8_1() {
if (process.platform != 'win32') {
return false;
}
var osVersion = require('../../common/osVersion');
return (osVersion.major <= 6 && osVersion.minor <= 3);
};
if (process.platform === 'win32' && isLowerThanOrEqualWindows8_1()) {
// Show balloon when notified.
notification.override({ notification.override({
// Send a notification event to the main process.
notification: function(title, options) { notification: function(title, options) {
ipc.send('notified', { ipc.send('notified', {
title: title, title: title,
options: options options: options
}); });
} },
});
}
else {
// Show window even if it is hidden/minimized when notification is clicked. // Show window even if it is hidden/minimized when notification is clicked.
notification.override({
onclick: function() { onclick: function() {
if (process.platform === 'win32') { if (process.platform === 'win32') {
// show() breaks Aero Snap state. // show() breaks Aero Snap state.
@ -132,4 +117,3 @@ else {
ipc.sendToHost('onNotificationClick'); ipc.sendToHost('onNotificationClick');
} }
}); });
}

View file

@ -3,5 +3,12 @@ var release_split = os.release().split('.');
module.exports = { module.exports = {
major: parseInt(release_split[0]), major: parseInt(release_split[0]),
minor: parseInt(release_split[1]) minor: parseInt(release_split[1]),
isLowerThanOrEqualWindows8_1: function() {
if (process.platform != 'win32') {
return false;
}
// consider Windows 7 and later.
return (this.major <= 6 && this.minor <= 3);
}
}; };

View file

@ -14,6 +14,7 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
var settings = require('./common/settings'); var settings = require('./common/settings');
const osVersion = require('./common/osVersion');
var certificateStore = require('./main/certificateStore').load(path.resolve(app.getPath('userData'), 'certificate.json')); var certificateStore = require('./main/certificateStore').load(path.resolve(app.getPath('userData'), 'certificate.json'));
var appMenu = require('./main/menus/app'); var appMenu = require('./main/menus/app');
const allowProtocolDialog = require('./main/allowProtocolDialog'); const allowProtocolDialog = require('./main/allowProtocolDialog');
@ -184,15 +185,19 @@ app.on('ready', function() {
mainWindow.focus(); mainWindow.focus();
}); });
ipc.on('notified', function(event, arg) { ipc.on('notified', function(event, arg) {
if (process.platform === 'win32') {
if (config.notifications.flashWindow === 2) {
mainWindow.flashFrame(true);
}
// On Windows 8.1 and Windows 8, a shortcut with a Application User Model ID must be installed to the Start screen.
// In current version, use tray balloon for notification
if (osVersion.isLowerThanOrEqualWindows8_1()) {
trayIcon.displayBalloon({ trayIcon.displayBalloon({
icon: path.resolve(__dirname, 'resources/appicon.png'), icon: path.resolve(__dirname, 'resources/appicon.png'),
title: arg.title, title: arg.title,
content: arg.options.body content: arg.options.body
}); });
}
/* Todo: add idle here */
if (config.notifications.flashWindow == 2) {
mainWindow.flashFrame(true);
} }
}); });
@ -215,7 +220,6 @@ app.on('ready', function() {
else { else {
trayIcon.setImage(trayImages.normal); trayIcon.setImage(trayImages.normal);
trayIcon.setToolTip(app.getName()); trayIcon.setToolTip(app.getName());
mainWindow.flashFrame(false);
} }
}); });
} }