Log whether OS supports native notifications
This commit is contained in:
parent
1f2a2e1d52
commit
4e6a03a91c
2 changed files with 32 additions and 18 deletions
|
@ -42,12 +42,14 @@
|
||||||
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({
|
||||||
isEnabled,
|
hasNotificationSupport,
|
||||||
isAppFocused,
|
isAppFocused,
|
||||||
isAudioNotificationEnabled,
|
isAudioNotificationEnabled,
|
||||||
isAudioNotificationSupported,
|
isAudioNotificationSupported,
|
||||||
|
isEnabled,
|
||||||
numNotifications,
|
numNotifications,
|
||||||
userSetting,
|
userSetting,
|
||||||
});
|
});
|
||||||
|
@ -102,16 +104,7 @@
|
||||||
|
|
||||||
drawAttention();
|
drawAttention();
|
||||||
|
|
||||||
if (config.polyfillNotifications) {
|
if (hasNotificationSupport) {
|
||||||
nodeNotifier.notify({
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
sound: false,
|
|
||||||
});
|
|
||||||
nodeNotifier.on('click', () => {
|
|
||||||
last.get('conversationId');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const notification = new Notification(title, {
|
const notification = new Notification(title, {
|
||||||
body: message,
|
body: message,
|
||||||
icon: iconUrl,
|
icon: iconUrl,
|
||||||
|
@ -123,6 +116,15 @@
|
||||||
this,
|
this,
|
||||||
last.get('conversationId')
|
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
|
||||||
|
|
|
@ -4,6 +4,7 @@ interface Environment {
|
||||||
isAudioNotificationSupported: boolean;
|
isAudioNotificationSupported: boolean;
|
||||||
isEnabled: boolean;
|
isEnabled: boolean;
|
||||||
numNotifications: number;
|
numNotifications: number;
|
||||||
|
hasNotificationSupport: boolean;
|
||||||
userSetting: UserSetting;
|
userSetting: UserSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ interface Status {
|
||||||
shouldClearNotifications: boolean;
|
shouldClearNotifications: boolean;
|
||||||
shouldPlayNotificationSound: boolean;
|
shouldPlayNotificationSound: boolean;
|
||||||
shouldShowNotifications: boolean;
|
shouldShowNotifications: boolean;
|
||||||
|
hasNotificationSupport: boolean;
|
||||||
type: Type;
|
type: Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,22 +25,30 @@ type Type =
|
||||||
| 'noNotifications'
|
| 'noNotifications'
|
||||||
| 'userSetting';
|
| 'userSetting';
|
||||||
|
|
||||||
export const getStatus = (environment: Environment): Status => {
|
export const getStatus = ({
|
||||||
|
hasNotificationSupport,
|
||||||
|
isAppFocused,
|
||||||
|
isAudioNotificationEnabled,
|
||||||
|
isAudioNotificationSupported,
|
||||||
|
isEnabled,
|
||||||
|
numNotifications,
|
||||||
|
userSetting,
|
||||||
|
}: Environment): Status => {
|
||||||
const type = ((): Type => {
|
const type = ((): Type => {
|
||||||
if (!environment.isEnabled) {
|
if (!isEnabled) {
|
||||||
return 'disabled';
|
return 'disabled';
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasNotifications = environment.numNotifications > 0;
|
const hasNotifications = numNotifications > 0;
|
||||||
if (!hasNotifications) {
|
if (!hasNotifications) {
|
||||||
return 'noNotifications';
|
return 'noNotifications';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (environment.isAppFocused) {
|
if (isAppFocused) {
|
||||||
return 'appIsFocused';
|
return 'appIsFocused';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (environment.userSetting === 'off') {
|
if (userSetting === 'off') {
|
||||||
return 'userSetting';
|
return 'userSetting';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +56,14 @@ export const getStatus = (environment: Environment): Status => {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const shouldPlayNotificationSound =
|
const shouldPlayNotificationSound =
|
||||||
environment.isAudioNotificationSupported &&
|
isAudioNotificationSupported &&
|
||||||
environment.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