From 3ad7ad203b5d12c14733bc9b296dedc836a5d338 Mon Sep 17 00:00:00 2001 From: Magnus Hauge Bakke Date: Sat, 2 Apr 2016 10:29:06 +0200 Subject: [PATCH] Add comments to electron app badge functions --- electron-globals.js | 7 +++++++ electron-main.js | 1 + js/notifications.js | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/electron-globals.js b/electron-globals.js index 9259511..05327c0 100644 --- a/electron-globals.js +++ b/electron-globals.js @@ -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; diff --git a/electron-main.js b/electron-main.js index 43420a2..5312ac8 100644 --- a/electron-main.js +++ b/electron-main.js @@ -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)); diff --git a/js/notifications.js b/js/notifications.js index 61fa024..9ef5fc1 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -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); }