Add comments to electron app badge functions
This commit is contained in:
parent
14d8f73532
commit
3ad7ad203b
3 changed files with 14 additions and 1 deletions
|
@ -1,9 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Global functions for electron app
|
||||||
|
*/
|
||||||
var ipc = require('electron').ipcRenderer;
|
var ipc = require('electron').ipcRenderer;
|
||||||
|
|
||||||
|
// Set app bagde
|
||||||
var setElectronBadge = function(value) {
|
var setElectronBadge = function(value) {
|
||||||
|
// Check ipc
|
||||||
if (ipc && typeof ipc.send === 'function') {
|
if (ipc && typeof ipc.send === 'function') {
|
||||||
|
// Send new badge value
|
||||||
ipc.send('badge', value);
|
ipc.send('badge', value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Export global variables and functions
|
||||||
global.setElectronBadge = setElectronBadge;
|
global.setElectronBadge = setElectronBadge;
|
||||||
|
|
|
@ -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 = 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');
|
||||||
|
|
||||||
|
// Listen for badge changes
|
||||||
ipcMain.on('badge', function(event, arg) {
|
ipcMain.on('badge', function(event, arg) {
|
||||||
if (process.platform === "darwin") {
|
if (process.platform === "darwin") {
|
||||||
app.dock.setBadge(String(arg));
|
app.dock.setBadge(String(arg));
|
||||||
|
|
|
@ -141,25 +141,30 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
|
||||||
bgColor: '#d00',
|
bgColor: '#d00',
|
||||||
textColor: '#fff'
|
textColor: '#fff'
|
||||||
});
|
});
|
||||||
|
// Set badge to notifications count
|
||||||
updateBadge(notifications);
|
updateBadge(notifications);
|
||||||
} else {
|
} else {
|
||||||
var unread = unreadCount('unread');
|
var unread = unreadCount('unread');
|
||||||
if (unread === 0) {
|
if (unread === 0) {
|
||||||
$rootScope.favico.reset();
|
$rootScope.favico.reset();
|
||||||
|
// Remove badge form app icon
|
||||||
updateBadge('');
|
updateBadge('');
|
||||||
} else {
|
} else {
|
||||||
$rootScope.favico.badge(unread, {
|
$rootScope.favico.badge(unread, {
|
||||||
bgColor: '#5CB85C',
|
bgColor: '#5CB85C',
|
||||||
textColor: '#ff0'
|
textColor: '#ff0'
|
||||||
});
|
});
|
||||||
|
// Set app badge to "." when only unread and no notifications
|
||||||
updateBadge(".");
|
updateBadge(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Update app badge (electron only)
|
||||||
var updateBadge = function(value) {
|
var updateBadge = function(value) {
|
||||||
|
|
||||||
// Get ipc
|
// Send new value to preloaded global function
|
||||||
|
// if it exists
|
||||||
if (typeof setElectronBadge === 'function') {
|
if (typeof setElectronBadge === 'function') {
|
||||||
setElectronBadge(value);
|
setElectronBadge(value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue