2015-12-22 07:34:24 -08:00
|
|
|
'use strict';
|
|
|
|
|
2016-09-25 07:14:01 -07:00
|
|
|
window.eval = global.eval = () => {
|
|
|
|
throw new Error('Sorry, Mattermost does not support window.eval() for security reasons.');
|
|
|
|
};
|
2016-07-22 14:03:03 -07:00
|
|
|
|
2016-01-30 07:50:43 -08:00
|
|
|
const React = require('react');
|
|
|
|
const ReactDOM = require('react-dom');
|
2016-10-30 08:40:34 -07:00
|
|
|
const {remote, ipcRenderer} = require('electron');
|
|
|
|
const MainPage = require('./components/MainPage.jsx');
|
2015-12-22 22:53:34 -08:00
|
|
|
|
2015-12-22 07:34:24 -08:00
|
|
|
const settings = require('../common/settings');
|
2016-09-25 07:14:01 -07:00
|
|
|
const badge = require('./js/badge');
|
2015-12-22 07:34:24 -08:00
|
|
|
|
2016-01-12 04:28:08 -08:00
|
|
|
remote.getCurrentWindow().removeAllListeners('focus');
|
|
|
|
|
2016-09-25 07:14:01 -07:00
|
|
|
var config;
|
|
|
|
try {
|
2016-12-26 05:55:27 -08:00
|
|
|
const configFile = remote.app.getPath('userData') + '/config.json';
|
2016-09-25 07:14:01 -07:00
|
|
|
config = settings.readFileSync(configFile);
|
|
|
|
} catch (e) {
|
|
|
|
window.location = 'settings.html';
|
|
|
|
}
|
|
|
|
if (config.teams.length === 0) {
|
|
|
|
window.location = 'settings.html';
|
|
|
|
}
|
|
|
|
|
|
|
|
function showUnreadBadgeWindows(unreadCount, mentionCount) {
|
|
|
|
function sendBadge(dataURL, description) {
|
2016-02-11 07:44:16 -08:00
|
|
|
// window.setOverlayIcon() does't work with NativeImage across remote boundaries.
|
|
|
|
// https://github.com/atom/electron/issues/4011
|
2016-05-20 11:06:38 -07:00
|
|
|
ipcRenderer.send('update-unread', {
|
2016-02-11 07:44:16 -08:00
|
|
|
overlayDataURL: dataURL,
|
2016-09-25 07:14:01 -07:00
|
|
|
description,
|
|
|
|
unreadCount,
|
|
|
|
mentionCount
|
2016-02-11 07:44:16 -08:00
|
|
|
});
|
2016-09-25 07:14:01 -07:00
|
|
|
}
|
2016-02-11 07:44:16 -08:00
|
|
|
|
|
|
|
if (mentionCount > 0) {
|
2016-07-12 06:01:01 -07:00
|
|
|
const dataURL = badge.createDataURL(mentionCount.toString());
|
2016-06-03 16:41:15 -07:00
|
|
|
sendBadge(dataURL, 'You have unread mentions (' + mentionCount + ')');
|
2016-07-15 04:04:14 -07:00
|
|
|
} else if (unreadCount > 0 && config.showUnreadBadge) {
|
2016-07-12 06:01:01 -07:00
|
|
|
const dataURL = badge.createDataURL('•');
|
2016-06-03 16:41:15 -07:00
|
|
|
sendBadge(dataURL, 'You have unread channels (' + unreadCount + ')');
|
2016-02-11 07:44:16 -08:00
|
|
|
} else {
|
2016-02-25 05:21:28 -08:00
|
|
|
sendBadge(null, 'You have no unread messages');
|
2016-02-11 07:44:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-25 07:14:01 -07:00
|
|
|
function showUnreadBadgeOSX(unreadCount, mentionCount) {
|
2016-02-11 07:44:16 -08:00
|
|
|
if (mentionCount > 0) {
|
|
|
|
remote.app.dock.setBadge(mentionCount.toString());
|
2016-07-15 04:04:14 -07:00
|
|
|
} else if (unreadCount > 0 && config.showUnreadBadge) {
|
2016-02-11 07:44:16 -08:00
|
|
|
remote.app.dock.setBadge('•');
|
|
|
|
} else {
|
|
|
|
remote.app.dock.setBadge('');
|
|
|
|
}
|
2016-04-06 08:49:20 -07:00
|
|
|
|
2016-05-20 11:06:38 -07:00
|
|
|
ipcRenderer.send('update-unread', {
|
2016-09-25 07:14:01 -07:00
|
|
|
unreadCount,
|
|
|
|
mentionCount
|
2016-04-06 08:49:20 -07:00
|
|
|
});
|
2016-02-11 07:44:16 -08:00
|
|
|
}
|
|
|
|
|
2016-09-25 07:14:01 -07:00
|
|
|
function showUnreadBadgeLinux(unreadCount, mentionCount) {
|
2016-06-29 12:28:43 -07:00
|
|
|
if (remote.app.isUnityRunning()) {
|
|
|
|
remote.app.setBadgeCount(mentionCount);
|
|
|
|
}
|
2016-05-07 13:21:07 -07:00
|
|
|
|
2016-05-20 11:06:38 -07:00
|
|
|
ipcRenderer.send('update-unread', {
|
2016-09-25 07:14:01 -07:00
|
|
|
unreadCount,
|
|
|
|
mentionCount
|
2016-05-07 13:21:07 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-25 07:14:01 -07:00
|
|
|
function showUnreadBadge(unreadCount, mentionCount) {
|
2015-12-23 00:06:17 -08:00
|
|
|
switch (process.platform) {
|
2016-09-25 07:14:01 -07:00
|
|
|
case 'win32':
|
|
|
|
showUnreadBadgeWindows(unreadCount, mentionCount);
|
|
|
|
break;
|
|
|
|
case 'darwin':
|
|
|
|
showUnreadBadgeOSX(unreadCount, mentionCount);
|
|
|
|
break;
|
|
|
|
case 'linux':
|
|
|
|
showUnreadBadgeLinux(unreadCount, mentionCount);
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-23 00:06:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 23:23:42 -07:00
|
|
|
ReactDOM.render(
|
2016-09-25 07:14:01 -07:00
|
|
|
<MainPage
|
2016-10-30 08:40:34 -07:00
|
|
|
disablewebsecurity={config.disablewebsecurity}
|
2016-09-25 07:14:01 -07:00
|
|
|
teams={config.teams}
|
|
|
|
onUnreadCountChange={showUnreadBadge}
|
|
|
|
/>,
|
2016-05-20 23:23:42 -07:00
|
|
|
document.getElementById('content')
|
|
|
|
);
|