mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-09-28 04:19:01 +00:00
Implemented mac app badge through listening for webview title changes
This commit is contained in:
parent
c1509e30d9
commit
199b1423e5
@ -22,6 +22,12 @@ ipc.on('params', function(message) {
|
||||
require('shell').openExternal(e.url);
|
||||
});
|
||||
|
||||
// We check for desktop notifications by listening to a title change in the webview
|
||||
// Not elegant, but it will have to do
|
||||
webView.addEventListener('page-title-set', function(event) {
|
||||
ipc.send('notification-message', 'TITLE_CHANGED');
|
||||
});
|
||||
|
||||
var webViewDiv = document.getElementById('webViewDiv');
|
||||
webViewDiv.appendChild(webView);
|
||||
|
||||
@ -49,8 +55,5 @@ ipc.on('params', function(message) {
|
||||
var webView = document.getElementById('webView');
|
||||
webView.undo();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
19
app/main.js
19
app/main.js
@ -2,10 +2,10 @@
|
||||
* Created by JiaHao on 4/7/15.
|
||||
*/
|
||||
|
||||
|
||||
var app = require('app');
|
||||
var fs = require('fs');
|
||||
var BrowserWindow = require('browser-window');
|
||||
var ipc = require('ipc');
|
||||
|
||||
const APP_ARGS_FILE_PATH = __dirname + '/targetUrl.txt';
|
||||
require('crash-reporter').start();
|
||||
@ -31,7 +31,7 @@ app.on('ready', function() {
|
||||
);
|
||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
||||
|
||||
//mainWindow.openDevTools();
|
||||
mainWindow.openDevTools();
|
||||
mainWindow.webContents.on('did-finish-load', function() {
|
||||
fs.readFile(APP_ARGS_FILE_PATH, 'utf8', function (error, data) {
|
||||
if (error) {
|
||||
@ -45,9 +45,22 @@ app.on('ready', function() {
|
||||
})
|
||||
});
|
||||
|
||||
// if the window is focused, clear the badge
|
||||
mainWindow.on('focus', function () {
|
||||
app.dock.setBadge('');
|
||||
});
|
||||
|
||||
mainWindow.on('closed', function() {
|
||||
mainWindow = null;
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
// listen for a notification message
|
||||
ipc.on('notification-message', function(event, arg) {
|
||||
console.log(arg); // prints "ping"
|
||||
if (arg === 'TITLE_CHANGED') {
|
||||
if (!mainWindow.isFocused()) {
|
||||
app.dock.setBadge('●');
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user