diff --git a/badge.png b/badge.png
new file mode 100644
index 00000000..dfc56224
Binary files /dev/null and b/badge.png differ
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);
+});