Use native notifications on all platforms

This commit is contained in:
Daniel Gasienica 2018-05-02 19:06:03 -04:00
parent 4e6a03a91c
commit c591c3ca55
4 changed files with 8 additions and 46 deletions

View file

@ -1,7 +1,5 @@
/* global Backbone: false */
/* global nodeNotifier: false */
/* global config: false */
/* global ConversationController: false */
/* global drawAttention: false */
/* global i18n: false */
@ -42,10 +40,8 @@
const isAudioNotificationSupported = Settings.isAudioNotificationSupported();
const numNotifications = this.length;
const userSetting = this.getUserSetting();
const hasNotificationSupport = !Boolean(config.polyfillNotifications);
const status = Signal.Notifications.getStatus({
hasNotificationSupport,
isAppFocused,
isAudioNotificationEnabled,
isAudioNotificationSupported,
@ -104,28 +100,14 @@
drawAttention();
if (hasNotificationSupport) {
const notification = new Notification(title, {
body: message,
icon: iconUrl,
tag: 'signal',
silent: !status.shouldPlayNotificationSound,
});
const notification = new Notification(title, {
body: message,
icon: iconUrl,
tag: 'signal',
silent: !status.shouldPlayNotificationSound,
});
notification.onclick = this.onClick.bind(
this,
last.get('conversationId')
);
} else {
nodeNotifier.notify({
title,
message,
sound: false,
});
nodeNotifier.on('click', () => {
last.get('conversationId');
});
}
notification.onclick = () => this.onClick(last.get('conversationId'));
// We don't want to notify the user about these same messages again
this.clear();

13
main.js
View file

@ -4,7 +4,6 @@ const os = require('os');
const _ = require('lodash');
const electron = require('electron');
const semver = require('semver');
const { BrowserWindow, app, Menu, shell, ipcMain: ipc } = electron;
@ -99,17 +98,6 @@ const loadLocale = require('./app/locale').load;
let logger;
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) {
return url.format({
pathname: path.join.apply(null, pathSegments),
@ -127,7 +115,6 @@ function prepareURL(pathSegments) {
node_version: process.versions.node,
hostname: os.hostname(),
appInstance: process.env.NODE_APP_INSTANCE,
polyfillNotifications: polyfillNotifications ? true : undefined, // for stringify()
proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy,
importMode: importMode ? true : undefined, // for stringify()
},

View file

@ -101,7 +101,6 @@ window.loadImage = require('blueimp-load-image');
window.nodeBuffer = Buffer;
window.nodeFetch = require('node-fetch');
window.nodeNotifier = require('node-notifier');
window.ProxyAgent = require('proxy-agent');
// Note: when modifying this file, consider whether our React Components or Backbone Views

View file

@ -4,7 +4,6 @@ interface Environment {
isAudioNotificationSupported: boolean;
isEnabled: boolean;
numNotifications: number;
hasNotificationSupport: boolean;
userSetting: UserSetting;
}
@ -12,7 +11,6 @@ interface Status {
shouldClearNotifications: boolean;
shouldPlayNotificationSound: boolean;
shouldShowNotifications: boolean;
hasNotificationSupport: boolean;
type: Type;
}
@ -26,7 +24,6 @@ type Type =
| 'userSetting';
export const getStatus = ({
hasNotificationSupport,
isAppFocused,
isAudioNotificationEnabled,
isAudioNotificationSupported,
@ -56,14 +53,11 @@ export const getStatus = ({
})();
const shouldPlayNotificationSound =
isAudioNotificationSupported &&
isAudioNotificationEnabled &&
hasNotificationSupport;
isAudioNotificationSupported && isAudioNotificationEnabled;
const shouldShowNotifications = type === 'ok';
const shouldClearNotifications = type === 'appIsFocused';
return {
hasNotificationSupport,
shouldClearNotifications,
shouldPlayNotificationSound,
shouldShowNotifications,