From b7ec057d4ab9bc9a3705aacf537635fbeef90a46 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Wed, 7 Oct 2015 22:55:00 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E8=AA=AD=E3=83=81=E3=83=A3=E3=83=B3?= =?UTF-8?q?=E3=83=8D=E3=83=AB=E3=81=8C=E3=81=82=E3=82=8B=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=80=81Windows=E3=81=AE=E3=82=BF=E3=82=B9=E3=82=AF=E3=83=90?= =?UTF-8?q?=E3=83=BC=E3=82=A2=E3=82=A4=E3=82=B3=E3=83=B3=E3=81=AB=E3=82=AA?= =?UTF-8?q?=E3=83=BC=E3=83=90=E3=83=BC=E3=83=AC=E3=82=A4=E3=82=A2=E3=82=A4?= =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- badge.png | Bin 0 -> 293 bytes index.html | 21 +++++++++++++++++++++ index.js | 24 ++++++++++++++++++++++++ main.js | 27 +++++++++++++++++---------- webview/mattermost.js | 8 ++++++++ 5 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 badge.png create mode 100644 index.html create mode 100644 index.js create mode 100644 webview/mattermost.js diff --git a/badge.png b/badge.png new file mode 100644 index 0000000000000000000000000000000000000000..dfc562243db9955b7b8a0a050f2fd00098a74cf6 GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ zFeZU8W4!u>V4$F6iEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0wEJY5_^ zEP9tt_U1ceAmALogJ(YPsvR6_ckr#MI=rsolVx|L$<#$EDYueNcK4+CADet&e!H--GyOrFX5o|VnN^(Utv_Yq<3hTiWt zX1!c?qm}JjRgi{>M3{t)llJrPHs${uKProuaPyqo-;2+)w>+O;O1ENa i|9IlAWBj=i)qNLUos?M+uu}-=S_V&7KbLh*2~7at$!$si literal 0 HcmV?d00001 diff --git a/index.html b/index.html new file mode 100644 index 00000000..3b6f1775 --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + Mattermost + + + + + + + + diff --git a/index.js b/index.js new file mode 100644 index 00000000..7487df12 --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +'use strict'; + +var ipc = require('ipc'); + +var webView = document.getElementById('mainWebview'); + +// Open in default browser. +webView.addEventListener('new-window', function(e) { + require('shell').openExternal(e.url); +}); + +// Count unread channels. +var timer = setInterval(function() { + webView.send('retrieveUnreadCount'); +}, 1000); + +webView.addEventListener('ipc-message', function(event){ + switch (event.channel) { + case 'retrieveUnreadCount': + var unreadCount = event.args[0]; + ipc.send('retrieveUnreadCount', unreadCount); + break; + } +}); diff --git a/main.js b/main.js index 61b1e814..3a9d94d5 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ var app = require('app'); // Module to control application life. var BrowserWindow = require('browser-window'); // Module to create native browser window. +var ipc = require('ipc'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. @@ -20,21 +21,27 @@ app.on('window-all-closed', function() { // initialization and is ready to create browser windows. app.on('ready', function() { // Create the browser window. - mainWindow = new BrowserWindow({width: 800, height: 600, 'node-integration': false}); + mainWindow = new BrowserWindow({width: 800, height: 600}); // and load the index.html of the app. - var baseUrl = 'http://MATTERMOST_URL'; - mainWindow.loadUrl(baseUrl); + mainWindow.loadUrl('file://' + __dirname + '/index.html'); // Open the DevTools. - //mainWindow.openDevTools(); + // mainWindow.openDevTools(); - // Hook open links - var webContents = mainWindow.webContents; - webContents.on('will-navigate', function(event, url){ - if (url.indexOf(baseUrl) != 0){ - event.preventDefault(); - require('shell').openExternal(url); + // 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: } }); diff --git a/webview/mattermost.js b/webview/mattermost.js new file mode 100644 index 00000000..782ee49f --- /dev/null +++ b/webview/mattermost.js @@ -0,0 +1,8 @@ +'use strict'; + +var ipc = require('ipc'); + +ipc.on('retrieveUnreadCount', function(){ + var unreadCount = document.getElementsByClassName('unread-title').length; + ipc.sendToHost('retrieveUnreadCount', unreadCount); +});