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'){