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,39 +97,23 @@ function isElementVisible(elem) {
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: function(title, options) {
ipc.send('notified', {
title: title,
options: options
});
}
});
}
else {
notification.override({
// Send a notification event to the main process.
notification: function(title, options) {
ipc.send('notified', {
title: title,
options: options
});
},
// Show window even if it is hidden/minimized when notification is clicked.
notification.override({
onclick: function() {
if (process.platform === 'win32') {
// show() breaks Aero Snap state.
electron.remote.getCurrentWindow().focus();
}
else {
electron.remote.getCurrentWindow().show();
}
ipc.sendToHost('onNotificationClick');
onclick: function() {
if (process.platform === 'win32') {
// show() breaks Aero Snap state.
electron.remote.getCurrentWindow().focus();
}
});
}
else {
electron.remote.getCurrentWindow().show();
}
ipc.sendToHost('onNotificationClick');
}
});