mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-24 08:33:36 +00:00
This PR adds a feature of showing app window when the notification are clicked Fixes: #358
35 lines
974 B
JavaScript
35 lines
974 B
JavaScript
'use strict';
|
|
|
|
const { remote, ipcRenderer } = require('electron');
|
|
|
|
const ConfigUtil = require(__dirname + '/utils/config-util.js');
|
|
|
|
const { app } = remote;
|
|
|
|
// From https://github.com/felixrieseberg/electron-windows-notifications#appusermodelid
|
|
// On windows 8 we have to explicitly set the appUserModelId otherwise notification won't work.
|
|
app.setAppUserModelId('org.zulip.zulip-electron');
|
|
|
|
const NativeNotification = window.Notification;
|
|
|
|
class baseNotification extends NativeNotification {
|
|
constructor(title, opts) {
|
|
opts.silent = ConfigUtil.getConfigItem('silent') || false;
|
|
super(title, opts);
|
|
|
|
this.addEventListener('click', () => {
|
|
ipcRenderer.send('focus-app');
|
|
});
|
|
}
|
|
static requestPermission() {
|
|
return; // eslint-disable-line no-useless-return
|
|
}
|
|
// Override default Notification permission
|
|
static get permission() {
|
|
return ConfigUtil.getConfigItem('showNotification') ? 'granted' : 'denied';
|
|
}
|
|
}
|
|
|
|
window.Notification = baseNotification;
|
|
|