From 84d3c377b4c75ede01a990c0fab5606f70ce432c Mon Sep 17 00:00:00 2001 From: Carmine D'Amico Date: Sun, 5 Jun 2016 12:50:15 +0200 Subject: [PATCH 1/3] first implementation for flash notification and settings to configure these --- src/browser/settings.jsx | 50 +++++++++++++++++++++++++++++++++++++++- src/common/settings.js | 5 +++- src/main.js | 5 ++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/browser/settings.jsx b/src/browser/settings.jsx index 224d9601..a5efcd97 100644 --- a/src/browser/settings.jsx +++ b/src/browser/settings.jsx @@ -49,7 +49,10 @@ var SettingsPage = React.createClass({ showTrayIcon: this.state.showTrayIcon, trayIconTheme: this.state.trayIconTheme, disablewebsecurity: this.state.disablewebsecurity, - version: settings.version + version: settings.version, + notifications: { + flashWindow: this.state.notifications.flashWindow + } }; settings.writeFileSync(this.props.configFile, config); if (process.platform === 'win32' || process.platform === 'linux') { @@ -96,6 +99,13 @@ var SettingsPage = React.createClass({ }); } }, + handleFlashWindowSetting: function(item) { + this.setState({ + notifications: { + flashWindow: item.state + } + }); + }, render: function() { var buttonStyle = { @@ -136,6 +146,40 @@ var SettingsPage = React.createClass({ ) : null; + var notificationSettings = [ + { + label: 'Never', + state: 0 + }, + { + label: 'Only when idle (after 10 seconds)', + state: 1 + }, + { + label: 'Always', + state: 2 + } + ]; + + var that = this; + var notificationElements = notificationSettings.map(function(item) { + var boundClick = that.handleFlashWindowSetting.bind(that, item); + return ( + + ); + }); + + var notifications = ( + + +

Notifications

+ { notificationElements } + +
+ ) + return ( @@ -150,6 +194,10 @@ var SettingsPage = React.createClass({ { teams_row } { options_row } + { notifications } +
+
+
diff --git a/src/common/settings.js b/src/common/settings.js index d9561194..093dcf8f 100644 --- a/src/common/settings.js +++ b/src/common/settings.js @@ -26,7 +26,10 @@ var loadDefault = function(version) { showTrayIcon: false, trayIconTheme: '', disablewebsecurity: true, - version: 1 + version: 1, + notifications: { + flashWindow: 0 // 0 = flash never, 1 = only when idle (after 10 seconds), 2 = always + } }; } } diff --git a/src/main.js b/src/main.js index baa80e49..ef3a7792 100644 --- a/src/main.js +++ b/src/main.js @@ -189,6 +189,10 @@ app.on('ready', function() { title: arg.title, content: arg.options.body }); + + if (config.notifications.flashWindow == 2) { + mainWindow.flashFrame(true); + } }); // Set overlay icon from dataURL @@ -209,6 +213,7 @@ app.on('ready', function() { } else { trayIcon.setImage(trayImages.normal); + mainWindow.flashFrame(false); trayIcon.setToolTip(app.getName()); } }); From 73a11ea398d3c2f7e66ae895c6161d6a9a37c252 Mon Sep 17 00:00:00 2001 From: Carmine D'Amico Date: Tue, 7 Jun 2016 22:17:44 +0200 Subject: [PATCH 2/3] added todo for idle notification and add a text to explain notification config --- src/browser/settings.jsx | 22 +++++++++++----------- src/main.js | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/browser/settings.jsx b/src/browser/settings.jsx index a5efcd97..1b7cddd3 100644 --- a/src/browser/settings.jsx +++ b/src/browser/settings.jsx @@ -151,10 +151,11 @@ var SettingsPage = React.createClass({ label: 'Never', state: 0 }, + /* ToDo: Idle isn't implemented yet { label: 'Only when idle (after 10 seconds)', state: 1 - }, + },*/ { label: 'Always', state: 2 @@ -165,19 +166,18 @@ var SettingsPage = React.createClass({ var notificationElements = notificationSettings.map(function(item) { var boundClick = that.handleFlashWindowSetting.bind(that, item); return ( - - ); + + ); }); var notifications = ( - - -

Notifications

- { notificationElements } - -
+ + +

Notifications

Configure, that the taskicon in the taskbar blinks when you were mentioned. + { notificationElements } + +
) return ( diff --git a/src/main.js b/src/main.js index ef3a7792..703a746a 100644 --- a/src/main.js +++ b/src/main.js @@ -190,6 +190,7 @@ app.on('ready', function() { content: arg.options.body }); + /* Todo: add idle here */ if (config.notifications.flashWindow == 2) { mainWindow.flashFrame(true); } @@ -213,8 +214,8 @@ app.on('ready', function() { } else { trayIcon.setImage(trayImages.normal); - mainWindow.flashFrame(false); trayIcon.setToolTip(app.getName()); + mainWindow.flashFrame(false); } }); } From 722807a5cb3ce6dbc819e26bdf2289c35163e57d Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Thu, 16 Jun 2016 22:10:55 +0900 Subject: [PATCH 3/3] Refactor notification to simplify event handling --- src/browser/webview/mattermost.js | 52 +++++++++++-------------------- src/common/osVersion.js | 9 +++++- src/main.js | 24 ++++++++------ 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/src/browser/webview/mattermost.js b/src/browser/webview/mattermost.js index ba9500c4..353efce5 100644 --- a/src/browser/webview/mattermost.js +++ b/src/browser/webview/mattermost.js @@ -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'); + } +}); diff --git a/src/common/osVersion.js b/src/common/osVersion.js index 8b320fbb..5be0c495 100644 --- a/src/common/osVersion.js +++ b/src/common/osVersion.js @@ -3,5 +3,12 @@ var release_split = os.release().split('.'); module.exports = { 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); + } }; diff --git a/src/main.js b/src/main.js index 703a746a..11de4d01 100644 --- a/src/main.js +++ b/src/main.js @@ -14,6 +14,7 @@ const fs = require('fs'); const path = require('path'); var settings = require('./common/settings'); +const osVersion = require('./common/osVersion'); var certificateStore = require('./main/certificateStore').load(path.resolve(app.getPath('userData'), 'certificate.json')); var appMenu = require('./main/menus/app'); const allowProtocolDialog = require('./main/allowProtocolDialog'); @@ -184,15 +185,19 @@ app.on('ready', function() { mainWindow.focus(); }); ipc.on('notified', function(event, arg) { - trayIcon.displayBalloon({ - icon: path.resolve(__dirname, 'resources/appicon.png'), - title: arg.title, - content: arg.options.body - }); - - /* Todo: add idle here */ - if (config.notifications.flashWindow == 2) { - mainWindow.flashFrame(true); + 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({ + icon: path.resolve(__dirname, 'resources/appicon.png'), + title: arg.title, + content: arg.options.body + }); + } } }); @@ -215,7 +220,6 @@ app.on('ready', function() { else { trayIcon.setImage(trayImages.normal); trayIcon.setToolTip(app.getName()); - mainWindow.flashFrame(false); } }); }