Add support for sound notifications on Windows 7 and 8

ding.mp3 is derived from /platform repository.
This commit is contained in:
Yuya Ochiai 2017-04-01 01:12:04 +09:00
parent 366c73b164
commit 2fa618c9c9
5 changed files with 21 additions and 0 deletions

View file

@ -15,6 +15,7 @@ Release date: TBD
#### Windows #### Windows
- Removed Japanese fonts support it's no longer necessary. - Removed Japanese fonts support it's no longer necessary.
- Added support for sound notifications on Windows 7 and 8.
### Bug Fixes ### Bug Fixes

View file

@ -55,6 +55,7 @@
"mocha-circleci-reporter": "0.0.2", "mocha-circleci-reporter": "0.0.2",
"npm-run-all": "^4.0.2", "npm-run-all": "^4.0.2",
"spectron": "~3.6.0", "spectron": "~3.6.0",
"url-loader": "^0.5.8",
"webpack": "^2.2.1", "webpack": "^2.2.1",
"webpack-dev-server": "^2.4.1", "webpack-dev-server": "^2.4.1",
"webpack-merge": "^3.0.0" "webpack-merge": "^3.0.0"

BIN
src/assets/ding.mp3 Normal file

Binary file not shown.

View file

@ -2,9 +2,17 @@
const OriginalNotification = Notification; const OriginalNotification = Notification;
const {remote} = require('electron'); const {remote} = require('electron');
const {throttle} = require('underscore');
const osVersion = require('../../common/osVersion');
const dingDataURL = require('../../assets/ding.mp3'); // https://github.com/mattermost/platform/blob/v3.7.3/webapp/images/ding.mp3
const appIconURL = `file:///${remote.app.getAppPath()}/assets/appicon.png`; const appIconURL = `file:///${remote.app.getAppPath()}/assets/appicon.png`;
const playDing = throttle(() => {
const ding = new Audio(dingDataURL);
ding.play();
}, 3000, {trailing: false});
function override(eventHandlers) { function override(eventHandlers) {
Notification = function constructor(title, options) { // eslint-disable-line no-global-assign, no-native-reassign Notification = function constructor(title, options) { // eslint-disable-line no-global-assign, no-native-reassign
if (process.platform === 'win32') { if (process.platform === 'win32') {
@ -18,6 +26,12 @@ function override(eventHandlers) {
if (eventHandlers.notification) { if (eventHandlers.notification) {
eventHandlers.notification(title, options); eventHandlers.notification(title, options);
} }
if (process.platform === 'win32' && osVersion.isLowerThanOrEqualWindows8_1()) {
if (!options.silent) {
playDing();
}
}
}; };
// static properties // static properties

View file

@ -25,6 +25,11 @@ module.exports = merge(base, {
plugins: ['transform-object-rest-spread'] plugins: ['transform-object-rest-spread']
} }
} }
}, {
test: /\.mp3$/,
use: {
loader: 'url-loader'
}
}] }]
}, },
node: { node: {