add monkeypatching notification support

This commit is contained in:
Contra 2016-01-22 10:44:42 -08:00
parent 55157afe9a
commit f75382d635
2 changed files with 34 additions and 4 deletions

View File

@ -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) => {

View File

@ -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;
}