未読チャンネルがある場合、Windowsのタスクバーアイコンにオーバーレイアイコンを表示する

This commit is contained in:
Yuya Ochiai 2015-10-07 22:55:00 +09:00
parent 4772281fce
commit b7ec057d4a
5 changed files with 70 additions and 10 deletions

BIN
badge.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

21
index.html Normal file
View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mattermost</title>
</head>
<body>
<!-- Modify src to your Mattermost url -->
<webview id="mainWebview" src="http://192.168.99.100:8065" autosize="on" preload="./webview/mattermost.js"></webview>
<style>
webview {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
<script src="./index.js"></script>
</body>
</html>

24
index.js Normal file
View file

@ -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;
}
});

27
main.js
View file

@ -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:
}
});

8
webview/mattermost.js Normal file
View file

@ -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);
});