mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-11 07:41:04 +00:00
Merge pull request #60 from contra/master
add notification monkey-patch, closes #38
This commit is contained in:
commit
bed4260f55
@ -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,32 @@
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
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