Electron: Set app badge in os x (darwin)

paste-quickfix
Magnus Hauge Bakke 9 years ago
parent c3aa336183
commit 14d8f73532
  1. 9
      electron-globals.js
  2. 8
      electron-main.js
  3. 2
      electron-start.html
  4. 1
      js/glowingbear.js
  5. 13
      js/notifications.js

@ -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.loadUrl('file://' + __dirname + '/electron-start.html');
/*
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.webContents.executeJavaScript("document.getElementById('glowingbear').openDevTools();");
});

@ -26,6 +26,6 @@ onload = function() {
</script>
</head>
<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>
</html>

@ -378,6 +378,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
notifications.updateFavico();
} else {
$rootScope.favico.reset();
notifications.updateBadge('');
}
});

@ -141,19 +141,31 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
bgColor: '#d00',
textColor: '#fff'
});
updateBadge(notifications);
} else {
var unread = unreadCount('unread');
if (unread === 0) {
$rootScope.favico.reset();
updateBadge('');
} else {
$rootScope.favico.badge(unread, {
bgColor: '#5CB85C',
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 */
var createHighlight = function(buffer, message) {
var title = '';
@ -204,6 +216,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
requestNotificationPermission: requestNotificationPermission,
updateTitle: updateTitle,
updateFavico: updateFavico,
updateBadge: updateBadge,
createHighlight: createHighlight,
cancelAll: cancelAll,
unreadCount: unreadCount

Loading…
Cancel
Save