fchat-rising/electron/notifications.ts

25 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2021-09-11 01:59:05 +00:00
import * as remote from '@electron/remote';
2017-09-02 01:50:31 +00:00
import core from '../chat/core';
import {Conversation} from '../chat/interfaces';
//tslint:disable-next-line:match-default-export-name
import BaseNotifications from '../chat/notifications';
2018-01-06 16:14:21 +00:00
const browserWindow = remote.getCurrentWindow();
2017-09-02 01:50:31 +00:00
export default class Notifications extends BaseNotifications {
2018-07-20 01:12:26 +00:00
async notify(conversation: Conversation, title: string, body: string, icon: string, sound: string): Promise<void> {
2018-04-11 19:17:58 +00:00
if(!this.shouldNotify(conversation)) return;
2018-08-10 16:59:37 +00:00
this.playSound(sound);
2018-01-06 16:14:21 +00:00
browserWindow.flashFrame(true);
2017-09-02 01:50:31 +00:00
if(core.state.settings.notifications) {
2018-07-20 01:12:26 +00:00
const notification = new Notification(title, this.getOptions(conversation, body, icon));
2017-09-02 01:50:31 +00:00
notification.onclick = () => {
browserWindow.webContents.send('show-tab', remote.getCurrentWebContents().id);
2017-09-02 01:50:31 +00:00
conversation.show();
2018-01-06 16:14:21 +00:00
browserWindow.focus();
2017-09-02 01:50:31 +00:00
notification.close();
};
}
}
2021-09-11 01:59:05 +00:00
}