From fe568143acddfe9e91eb9a24eff91520198355ba Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Thu, 8 Oct 2015 22:15:31 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E8=AA=AD=E3=83=90=E3=83=83=E3=82=B8?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E7=94=A8=E3=81=AE=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=82=92=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 19 +++++++++++++++++-- main.js | 17 ----------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 7487df12..cd661bbc 100644 --- a/index.js +++ b/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; } }); diff --git a/main.js b/main.js index 6a47e1cc..f4338003 100644 --- a/main.js +++ b/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'){