Add comments to electron app badge functions

This commit is contained in:
Magnus Hauge Bakke 2016-04-02 10:29:06 +02:00
parent 14d8f73532
commit 3ad7ad203b
3 changed files with 14 additions and 1 deletions

View file

@ -1,9 +1,16 @@
/**
* Global functions for electron app
*/
var ipc = require('electron').ipcRenderer;
// Set app bagde
var setElectronBadge = function(value) {
// Check ipc
if (ipc && typeof ipc.send === 'function') {
// Send new badge value
ipc.send('badge', value);
}
};
// Export global variables and functions
global.setElectronBadge = setElectronBadge;

View file

@ -188,6 +188,7 @@
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');
// Listen for badge changes
ipcMain.on('badge', function(event, arg) {
if (process.platform === "darwin") {
app.dock.setBadge(String(arg));

View file

@ -141,25 +141,30 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
bgColor: '#d00',
textColor: '#fff'
});
// Set badge to notifications count
updateBadge(notifications);
} else {
var unread = unreadCount('unread');
if (unread === 0) {
$rootScope.favico.reset();
// Remove badge form app icon
updateBadge('');
} else {
$rootScope.favico.badge(unread, {
bgColor: '#5CB85C',
textColor: '#ff0'
});
// Set app badge to "." when only unread and no notifications
updateBadge(".");
}
}
};
// Update app badge (electron only)
var updateBadge = function(value) {
// Get ipc
// Send new value to preloaded global function
// if it exists
if (typeof setElectronBadge === 'function') {
setElectronBadge(value);
}