mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-11 15:51:06 +00:00
add monkeypatching notification support
This commit is contained in:
parent
55157afe9a
commit
f75382d635
@ -94,6 +94,14 @@ app.on('ready', function () {
|
||||
});
|
||||
}
|
||||
|
||||
mainWindow.on('notification', function (title) {
|
||||
if (!isOSX() || mainWindow.isFocused()) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.dock.setBadge('●');
|
||||
});
|
||||
|
||||
mainWindow.webContents.on('new-window', function (event, urlToGo) {
|
||||
if (linkIsInternal(appArgs.targetUrl, urlToGo)) {
|
||||
return;
|
||||
@ -108,9 +116,7 @@ app.on('ready', function () {
|
||||
if (!isOSX()) {
|
||||
return;
|
||||
}
|
||||
if (appArgs.badge || appArgs.counter) {
|
||||
app.dock.setBadge('');
|
||||
}
|
||||
app.dock.setBadge('');
|
||||
});
|
||||
|
||||
mainWindow.on('close', (e) => {
|
||||
|
@ -4,11 +4,35 @@
|
||||
|
||||
var ipc = require('electron').ipcRenderer;
|
||||
|
||||
// monkeypatch window.Notification
|
||||
hookNotify(function(title, opt){
|
||||
ipc.emit('notification', title, opt);
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
// do things
|
||||
// do things here
|
||||
Notification.requestPermission().then(function(){
|
||||
new Notification('test')
|
||||
})
|
||||
});
|
||||
|
||||
ipc.on('params', function (event, message) {
|
||||
var appArgs = JSON.parse(message);
|
||||
console.log('nativefier.json', appArgs);
|
||||
});
|
||||
|
||||
function hookNotify(cb){
|
||||
var oldNotify = window.Notification;
|
||||
var newNotify = function (title, opt) {
|
||||
cb(title, opt);
|
||||
return new oldNotify(title, opt);
|
||||
};
|
||||
newNotify.requestPermission = oldNotify.requestPermission.bind(oldNotify);
|
||||
Object.defineProperty(newNotify, 'permission', {
|
||||
get: function() {
|
||||
return oldNotify.permission;
|
||||
}
|
||||
});
|
||||
|
||||
window.Notification = newNotify;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user