mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-06-17 11:22:20 +00:00
Show application window on notification click (#640)
This commit is contained in:
parent
e228f0cff8
commit
27ea3fc4a3
|
@ -322,6 +322,10 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipcMain.on('notification-click', () => {
|
||||||
|
mainWindow.show();
|
||||||
|
});
|
||||||
|
|
||||||
mainWindow.webContents.on('new-window', onNewWindow);
|
mainWindow.webContents.on('new-window', onNewWindow);
|
||||||
mainWindow.webContents.on('will-navigate', onWillNavigate);
|
mainWindow.webContents.on('will-navigate', onWillNavigate);
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,19 @@ import fs from 'fs';
|
||||||
const INJECT_JS_PATH = path.join(__dirname, '../../', 'inject/inject.js');
|
const INJECT_JS_PATH = path.join(__dirname, '../../', 'inject/inject.js');
|
||||||
const log = require('loglevel');
|
const log = require('loglevel');
|
||||||
/**
|
/**
|
||||||
* Patches window.Notification to set a callback on a new Notification
|
* Patches window.Notification to:
|
||||||
* @param callback
|
* - set a callback on a new Notification
|
||||||
|
* - set a callback for clicks on notifications
|
||||||
|
* @param createCallback
|
||||||
|
* @param clickCallback
|
||||||
*/
|
*/
|
||||||
function setNotificationCallback(callback) {
|
function setNotificationCallback(createCallback, clickCallback) {
|
||||||
const OldNotify = window.Notification;
|
const OldNotify = window.Notification;
|
||||||
const newNotify = (title, opt) => {
|
const newNotify = (title, opt) => {
|
||||||
callback(title, opt);
|
createCallback(title, opt);
|
||||||
return new OldNotify(title, opt);
|
const instance = new OldNotify(title, opt);
|
||||||
|
instance.addEventListener('click', clickCallback);
|
||||||
|
return instance;
|
||||||
};
|
};
|
||||||
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
|
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
|
||||||
Object.defineProperty(newNotify, 'permission', {
|
Object.defineProperty(newNotify, 'permission', {
|
||||||
|
@ -35,9 +40,14 @@ function injectScripts() {
|
||||||
require(INJECT_JS_PATH);
|
require(INJECT_JS_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
setNotificationCallback((title, opt) => {
|
function notifyNotificationCreate(title, opt) {
|
||||||
ipcRenderer.send('notification', title, opt);
|
ipcRenderer.send('notification', title, opt);
|
||||||
});
|
}
|
||||||
|
function notifyNotificationClick() {
|
||||||
|
ipcRenderer.send('notification-click');
|
||||||
|
}
|
||||||
|
|
||||||
|
setNotificationCallback(notifyNotificationCreate, notifyNotificationClick);
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
injectScripts();
|
injectScripts();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user