Use native notifications on all platforms
This commit is contained in:
parent
4e6a03a91c
commit
c591c3ca55
4 changed files with 8 additions and 46 deletions
|
@ -1,7 +1,5 @@
|
||||||
/* global Backbone: false */
|
/* global Backbone: false */
|
||||||
/* global nodeNotifier: false */
|
|
||||||
|
|
||||||
/* global config: false */
|
|
||||||
/* global ConversationController: false */
|
/* global ConversationController: false */
|
||||||
/* global drawAttention: false */
|
/* global drawAttention: false */
|
||||||
/* global i18n: false */
|
/* global i18n: false */
|
||||||
|
@ -42,10 +40,8 @@
|
||||||
const isAudioNotificationSupported = Settings.isAudioNotificationSupported();
|
const isAudioNotificationSupported = Settings.isAudioNotificationSupported();
|
||||||
const numNotifications = this.length;
|
const numNotifications = this.length;
|
||||||
const userSetting = this.getUserSetting();
|
const userSetting = this.getUserSetting();
|
||||||
const hasNotificationSupport = !Boolean(config.polyfillNotifications);
|
|
||||||
|
|
||||||
const status = Signal.Notifications.getStatus({
|
const status = Signal.Notifications.getStatus({
|
||||||
hasNotificationSupport,
|
|
||||||
isAppFocused,
|
isAppFocused,
|
||||||
isAudioNotificationEnabled,
|
isAudioNotificationEnabled,
|
||||||
isAudioNotificationSupported,
|
isAudioNotificationSupported,
|
||||||
|
@ -104,7 +100,6 @@
|
||||||
|
|
||||||
drawAttention();
|
drawAttention();
|
||||||
|
|
||||||
if (hasNotificationSupport) {
|
|
||||||
const notification = new Notification(title, {
|
const notification = new Notification(title, {
|
||||||
body: message,
|
body: message,
|
||||||
icon: iconUrl,
|
icon: iconUrl,
|
||||||
|
@ -112,20 +107,7 @@
|
||||||
silent: !status.shouldPlayNotificationSound,
|
silent: !status.shouldPlayNotificationSound,
|
||||||
});
|
});
|
||||||
|
|
||||||
notification.onclick = this.onClick.bind(
|
notification.onclick = () => this.onClick(last.get('conversationId'));
|
||||||
this,
|
|
||||||
last.get('conversationId')
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
nodeNotifier.notify({
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
sound: false,
|
|
||||||
});
|
|
||||||
nodeNotifier.on('click', () => {
|
|
||||||
last.get('conversationId');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't want to notify the user about these same messages again
|
// We don't want to notify the user about these same messages again
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
13
main.js
13
main.js
|
@ -4,7 +4,6 @@ const os = require('os');
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const semver = require('semver');
|
|
||||||
|
|
||||||
const { BrowserWindow, app, Menu, shell, ipcMain: ipc } = electron;
|
const { BrowserWindow, app, Menu, shell, ipcMain: ipc } = electron;
|
||||||
|
|
||||||
|
@ -99,17 +98,6 @@ const loadLocale = require('./app/locale').load;
|
||||||
let logger;
|
let logger;
|
||||||
let locale;
|
let locale;
|
||||||
|
|
||||||
const WINDOWS_8 = '8.0.0';
|
|
||||||
const osRelease = os.release();
|
|
||||||
const polyfillNotifications =
|
|
||||||
os.platform() === 'win32' && semver.lt(osRelease, WINDOWS_8);
|
|
||||||
console.log(
|
|
||||||
'OS Release:',
|
|
||||||
osRelease,
|
|
||||||
'- notifications polyfill?',
|
|
||||||
polyfillNotifications
|
|
||||||
);
|
|
||||||
|
|
||||||
function prepareURL(pathSegments) {
|
function prepareURL(pathSegments) {
|
||||||
return url.format({
|
return url.format({
|
||||||
pathname: path.join.apply(null, pathSegments),
|
pathname: path.join.apply(null, pathSegments),
|
||||||
|
@ -127,7 +115,6 @@ function prepareURL(pathSegments) {
|
||||||
node_version: process.versions.node,
|
node_version: process.versions.node,
|
||||||
hostname: os.hostname(),
|
hostname: os.hostname(),
|
||||||
appInstance: process.env.NODE_APP_INSTANCE,
|
appInstance: process.env.NODE_APP_INSTANCE,
|
||||||
polyfillNotifications: polyfillNotifications ? true : undefined, // for stringify()
|
|
||||||
proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy,
|
proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy,
|
||||||
importMode: importMode ? true : undefined, // for stringify()
|
importMode: importMode ? true : undefined, // for stringify()
|
||||||
},
|
},
|
||||||
|
|
|
@ -101,7 +101,6 @@ window.loadImage = require('blueimp-load-image');
|
||||||
|
|
||||||
window.nodeBuffer = Buffer;
|
window.nodeBuffer = Buffer;
|
||||||
window.nodeFetch = require('node-fetch');
|
window.nodeFetch = require('node-fetch');
|
||||||
window.nodeNotifier = require('node-notifier');
|
|
||||||
window.ProxyAgent = require('proxy-agent');
|
window.ProxyAgent = require('proxy-agent');
|
||||||
|
|
||||||
// Note: when modifying this file, consider whether our React Components or Backbone Views
|
// Note: when modifying this file, consider whether our React Components or Backbone Views
|
||||||
|
|
|
@ -4,7 +4,6 @@ interface Environment {
|
||||||
isAudioNotificationSupported: boolean;
|
isAudioNotificationSupported: boolean;
|
||||||
isEnabled: boolean;
|
isEnabled: boolean;
|
||||||
numNotifications: number;
|
numNotifications: number;
|
||||||
hasNotificationSupport: boolean;
|
|
||||||
userSetting: UserSetting;
|
userSetting: UserSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +11,6 @@ interface Status {
|
||||||
shouldClearNotifications: boolean;
|
shouldClearNotifications: boolean;
|
||||||
shouldPlayNotificationSound: boolean;
|
shouldPlayNotificationSound: boolean;
|
||||||
shouldShowNotifications: boolean;
|
shouldShowNotifications: boolean;
|
||||||
hasNotificationSupport: boolean;
|
|
||||||
type: Type;
|
type: Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +24,6 @@ type Type =
|
||||||
| 'userSetting';
|
| 'userSetting';
|
||||||
|
|
||||||
export const getStatus = ({
|
export const getStatus = ({
|
||||||
hasNotificationSupport,
|
|
||||||
isAppFocused,
|
isAppFocused,
|
||||||
isAudioNotificationEnabled,
|
isAudioNotificationEnabled,
|
||||||
isAudioNotificationSupported,
|
isAudioNotificationSupported,
|
||||||
|
@ -56,14 +53,11 @@ export const getStatus = ({
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const shouldPlayNotificationSound =
|
const shouldPlayNotificationSound =
|
||||||
isAudioNotificationSupported &&
|
isAudioNotificationSupported && isAudioNotificationEnabled;
|
||||||
isAudioNotificationEnabled &&
|
|
||||||
hasNotificationSupport;
|
|
||||||
const shouldShowNotifications = type === 'ok';
|
const shouldShowNotifications = type === 'ok';
|
||||||
const shouldClearNotifications = type === 'appIsFocused';
|
const shouldClearNotifications = type === 'appIsFocused';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hasNotificationSupport,
|
|
||||||
shouldClearNotifications,
|
shouldClearNotifications,
|
||||||
shouldPlayNotificationSound,
|
shouldPlayNotificationSound,
|
||||||
shouldShowNotifications,
|
shouldShowNotifications,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue