mattermost-desktop/src/browser/index.jsx

98 lines
2.6 KiB
React
Raw Normal View History

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-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');
2016-12-25 07:44:44 -08:00
const AppConfig = require('./config/AppConfig.js');
2016-09-25 07:14:01 -07:00
const badge = require('./js/badge');
2015-12-22 07:34:24 -08:00
remote.getCurrentWindow().removeAllListeners('focus');
2016-12-25 08:03:35 -08:00
if (AppConfig.data.teams.length === 0) {
2016-09-25 07:14:01 -07:00
window.location = 'settings.html';
}
function showUnreadBadgeWindows(unreadCount, mentionCount) {
function sendBadge(dataURL, description) {
// window.setOverlayIcon() does't work with NativeImage across remote boundaries.
// https://github.com/atom/electron/issues/4011
ipcRenderer.send('update-unread', {
overlayDataURL: dataURL,
2016-09-25 07:14:01 -07:00
description,
unreadCount,
mentionCount
});
2016-09-25 07:14:01 -07:00
}
if (mentionCount > 0) {
const dataURL = badge.createDataURL(mentionCount.toString());
2016-06-03 16:41:15 -07:00
sendBadge(dataURL, 'You have unread mentions (' + mentionCount + ')');
2016-12-25 08:03:35 -08:00
} else if (unreadCount > 0 && AppConfig.data.showUnreadBadge) {
const dataURL = badge.createDataURL('•');
2016-06-03 16:41:15 -07:00
sendBadge(dataURL, 'You have unread channels (' + unreadCount + ')');
} else {
sendBadge(null, 'You have no unread messages');
}
}
2016-09-25 07:14:01 -07:00
function showUnreadBadgeOSX(unreadCount, mentionCount) {
if (mentionCount > 0) {
remote.app.dock.setBadge(mentionCount.toString());
2016-12-25 08:03:35 -08:00
} else if (unreadCount > 0 && AppConfig.data.showUnreadBadge) {
remote.app.dock.setBadge('•');
} else {
remote.app.dock.setBadge('');
}
2016-04-06 08:49:20 -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-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);
}
ipcRenderer.send('update-unread', {
2016-09-25 07:14:01 -07:00
unreadCount,
mentionCount
});
}
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-12-25 08:03:35 -08:00
function teamConfigChange(teams) {
AppConfig.set('teams', teams);
}
ReactDOM.render(
2016-09-25 07:14:01 -07:00
<MainPage
2016-12-25 08:03:35 -08:00
disablewebsecurity={AppConfig.data.disablewebsecurity}
teams={AppConfig.data.teams}
2016-09-25 07:14:01 -07:00
onUnreadCountChange={showUnreadBadge}
2016-12-25 08:03:35 -08:00
onTeamConfigChange={teamConfigChange}
2016-09-25 07:14:01 -07:00
/>,
document.getElementById('content')
);