Electron: Set app badge in os x (darwin)
This commit is contained in:
parent
c3aa336183
commit
14d8f73532
5 changed files with 29 additions and 4 deletions
9
electron-globals.js
Normal file
9
electron-globals.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
var ipc = require('electron').ipcRenderer;
|
||||||
|
|
||||||
|
var setElectronBadge = function(value) {
|
||||||
|
if (ipc && typeof ipc.send === 'function') {
|
||||||
|
ipc.send('badge', value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
global.setElectronBadge = setElectronBadge;
|
|
@ -187,10 +187,12 @@
|
||||||
|
|
||||||
mainWindow = new BrowserWindow({width: 1280, height: 800, 'min-width': 1024, 'min-height': 600, 'autoHideMenuBar': true, 'web-security': true, 'java': false, 'icon':'file://'+__dirname + 'assets/img/favicon.png'});
|
mainWindow = new BrowserWindow({width: 1280, height: 800, 'min-width': 1024, 'min-height': 600, 'autoHideMenuBar': true, 'web-security': true, 'java': false, 'icon':'file://'+__dirname + 'assets/img/favicon.png'});
|
||||||
mainWindow.loadUrl('file://' + __dirname + '/electron-start.html');
|
mainWindow.loadUrl('file://' + __dirname + '/electron-start.html');
|
||||||
/*
|
|
||||||
ipcMain.on('badge', function(event, arg) {
|
ipcMain.on('badge', function(event, arg) {
|
||||||
app.dock.setBadge(String(arg));
|
if (process.platform === "darwin") {
|
||||||
});*/
|
app.dock.setBadge(String(arg));
|
||||||
|
}
|
||||||
|
});
|
||||||
mainWindow.on('devtools-opened', function() {
|
mainWindow.on('devtools-opened', function() {
|
||||||
mainWindow.webContents.executeJavaScript("document.getElementById('glowingbear').openDevTools();");
|
mainWindow.webContents.executeJavaScript("document.getElementById('glowingbear').openDevTools();");
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,6 +26,6 @@ onload = function() {
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<webview id="glowingbear" src="index.html" style="position:fixed; top:0; left:0; bottom:0; right:0;"></webview>
|
<webview preload="electron-globals.js" id="glowingbear" src="index.html" style="position:fixed; top:0; left:0; bottom:0; right:0;"></webview>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -378,6 +378,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
notifications.updateFavico();
|
notifications.updateFavico();
|
||||||
} else {
|
} else {
|
||||||
$rootScope.favico.reset();
|
$rootScope.favico.reset();
|
||||||
|
notifications.updateBadge('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -141,19 +141,31 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
|
||||||
bgColor: '#d00',
|
bgColor: '#d00',
|
||||||
textColor: '#fff'
|
textColor: '#fff'
|
||||||
});
|
});
|
||||||
|
updateBadge(notifications);
|
||||||
} else {
|
} else {
|
||||||
var unread = unreadCount('unread');
|
var unread = unreadCount('unread');
|
||||||
if (unread === 0) {
|
if (unread === 0) {
|
||||||
$rootScope.favico.reset();
|
$rootScope.favico.reset();
|
||||||
|
updateBadge('');
|
||||||
} else {
|
} else {
|
||||||
$rootScope.favico.badge(unread, {
|
$rootScope.favico.badge(unread, {
|
||||||
bgColor: '#5CB85C',
|
bgColor: '#5CB85C',
|
||||||
textColor: '#ff0'
|
textColor: '#ff0'
|
||||||
});
|
});
|
||||||
|
updateBadge(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var updateBadge = function(value) {
|
||||||
|
|
||||||
|
// Get ipc
|
||||||
|
if (typeof setElectronBadge === 'function') {
|
||||||
|
setElectronBadge(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/* Function gets called from bufferLineAdded code if user should be notified */
|
/* Function gets called from bufferLineAdded code if user should be notified */
|
||||||
var createHighlight = function(buffer, message) {
|
var createHighlight = function(buffer, message) {
|
||||||
var title = '';
|
var title = '';
|
||||||
|
@ -204,6 +216,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
|
||||||
requestNotificationPermission: requestNotificationPermission,
|
requestNotificationPermission: requestNotificationPermission,
|
||||||
updateTitle: updateTitle,
|
updateTitle: updateTitle,
|
||||||
updateFavico: updateFavico,
|
updateFavico: updateFavico,
|
||||||
|
updateBadge: updateBadge,
|
||||||
createHighlight: createHighlight,
|
createHighlight: createHighlight,
|
||||||
cancelAll: cancelAll,
|
cancelAll: cancelAll,
|
||||||
unreadCount: unreadCount
|
unreadCount: unreadCount
|
||||||
|
|
Loading…
Reference in a new issue