未読バッジ表示用のコードを整理
This commit is contained in:
parent
0ed0e16223
commit
fe568143ac
19
index.js
19
index.js
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var ipc = require('ipc');
|
||||
var remote = require('remote');
|
||||
|
||||
var webView = document.getElementById('mainWebview');
|
||||
|
||||
|
@ -14,11 +14,26 @@ var timer = setInterval(function() {
|
|||
webView.send('retrieveUnreadCount');
|
||||
}, 1000);
|
||||
|
||||
var showUnreadBadge = function(unreadCount){
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
var window = remote.getCurrentWindow();
|
||||
if(unreadCount > 0){
|
||||
window.setOverlayIcon(__dirname + '/badge.png', 'You have unread channels.');
|
||||
}
|
||||
else{
|
||||
window.setOverlayIcon(null, '');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
webView.addEventListener('ipc-message', function(event){
|
||||
switch (event.channel) {
|
||||
case 'retrieveUnreadCount':
|
||||
var unreadCount = event.args[0];
|
||||
ipc.send('retrieveUnreadCount', unreadCount);
|
||||
showUnreadBadge(unreadCount);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
17
main.js
17
main.js
|
@ -2,7 +2,6 @@
|
|||
|
||||
var app = require('app'); // Module to control application life.
|
||||
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
||||
var ipc = require('ipc');
|
||||
var Menu = require('menu');
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
|
@ -31,22 +30,6 @@ app.on('ready', function() {
|
|||
// Open the DevTools.
|
||||
// mainWindow.openDevTools();
|
||||
|
||||
// Show badges for unread channels.
|
||||
ipc.on('retrieveUnreadCount', function(event, arg){
|
||||
console.log(arg);
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
if(arg > 0){
|
||||
mainWindow.setOverlayIcon(__dirname + '/badge.png', 'You have unread channels.');
|
||||
}
|
||||
else{
|
||||
mainWindow.setOverlayIcon(null, '');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.on('close', function(event){
|
||||
// Minimize the window for close button.
|
||||
if(process.platform==='win32'){
|
||||
|
|
Loading…
Reference in a new issue