Use balloon notification on Windows from 7 to 8.1

This commit is contained in:
Yuya Ochiai
2015-11-28 14:23:02 +09:00
parent 6f18b921b2
commit 47ac5f102d
2 changed files with 29 additions and 7 deletions

7
src/common/osVersion.js Normal file
View File

@@ -0,0 +1,7 @@
var os = require('os');
var release_split = os.release().split('.');
module.exports = {
major: parseInt(release_split[0]),
minor: parseInt(release_split[1])
};

View File

@@ -2,15 +2,26 @@
const electron = require('electron');
const ipc = electron.ipcRenderer;
const NativeNotification = Notification;
ipc.on('retrieveUnreadCount', function() {
var unreadCount = document.getElementsByClassName('unread-title').length;
ipc.sendToHost('retrieveUnreadCount', unreadCount);
console.log(isLowerThanOrEqualWindows8_1());
});
// 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);
};
// Show balloon when notified.
/*
if (process.platform === 'win32') {
function overrideNotificationWithBalloon() {
Notification = function(title, options) {
ipc.send('notified', {
title: title,
@@ -21,13 +32,10 @@ if (process.platform === 'win32') {
callback('granted');
};
Notification.prototype.close = function() {};
}
*/
};
// Show window even if it is hidden/minimized when notification is clicked.
var NativeNotification = null;
if (process.platform === 'darwin' || process.platform === 'win32') {
NativeNotification = Notification;
function overrideNotification() {
Notification = function(title, options) {
this.notification = new NativeNotification(title, options);
};
@@ -44,3 +52,10 @@ if (process.platform === 'darwin' || process.platform === 'win32') {
};
});
}
if (process.platform === 'win32' && isLowerThanOrEqualWindows8_1()) {
overrideNotificationWithBalloon();
}
else {
overrideNotification();
}