Use balloon notification on Windows from 7 to 8.1
This commit is contained in:
7
src/common/osVersion.js
Normal file
7
src/common/osVersion.js
Normal 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])
|
||||||
|
};
|
@@ -2,15 +2,26 @@
|
|||||||
|
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const ipc = electron.ipcRenderer;
|
const ipc = electron.ipcRenderer;
|
||||||
|
const NativeNotification = Notification;
|
||||||
|
|
||||||
ipc.on('retrieveUnreadCount', function() {
|
ipc.on('retrieveUnreadCount', function() {
|
||||||
var unreadCount = document.getElementsByClassName('unread-title').length;
|
var unreadCount = document.getElementsByClassName('unread-title').length;
|
||||||
ipc.sendToHost('retrieveUnreadCount', unreadCount);
|
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.
|
// Show balloon when notified.
|
||||||
/*
|
function overrideNotificationWithBalloon() {
|
||||||
if (process.platform === 'win32') {
|
|
||||||
Notification = function(title, options) {
|
Notification = function(title, options) {
|
||||||
ipc.send('notified', {
|
ipc.send('notified', {
|
||||||
title: title,
|
title: title,
|
||||||
@@ -21,13 +32,10 @@ if (process.platform === 'win32') {
|
|||||||
callback('granted');
|
callback('granted');
|
||||||
};
|
};
|
||||||
Notification.prototype.close = function() {};
|
Notification.prototype.close = function() {};
|
||||||
}
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
// Show window even if it is hidden/minimized when notification is clicked.
|
// Show window even if it is hidden/minimized when notification is clicked.
|
||||||
var NativeNotification = null;
|
function overrideNotification() {
|
||||||
if (process.platform === 'darwin' || process.platform === 'win32') {
|
|
||||||
NativeNotification = Notification;
|
|
||||||
Notification = function(title, options) {
|
Notification = function(title, options) {
|
||||||
this.notification = new NativeNotification(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();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user