'use strict'; window.eval = global.eval = () => { throw new Error('Sorry, Mattermost does not support window.eval() for security reasons.'); }; const React = require('react'); const ReactDOM = require('react-dom'); const {remote, ipcRenderer} = require('electron'); const MainPage = require('./components/MainPage.jsx'); const settings = require('../common/settings'); const badge = require('./js/badge'); remote.getCurrentWindow().removeAllListeners('focus'); var config; try { var configFile = remote.getGlobal('config-file'); 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) { // window.setOverlayIcon() does't work with NativeImage across remote boundaries. // https://github.com/atom/electron/issues/4011 ipcRenderer.send('update-unread', { overlayDataURL: dataURL, description, unreadCount, mentionCount }); } if (mentionCount > 0) { const dataURL = badge.createDataURL(mentionCount.toString()); sendBadge(dataURL, 'You have unread mentions (' + mentionCount + ')'); } else if (unreadCount > 0 && config.showUnreadBadge) { const dataURL = badge.createDataURL('•'); sendBadge(dataURL, 'You have unread channels (' + unreadCount + ')'); } else { sendBadge(null, 'You have no unread messages'); } } function showUnreadBadgeOSX(unreadCount, mentionCount) { if (mentionCount > 0) { remote.app.dock.setBadge(mentionCount.toString()); } else if (unreadCount > 0 && config.showUnreadBadge) { remote.app.dock.setBadge('•'); } else { remote.app.dock.setBadge(''); } ipcRenderer.send('update-unread', { unreadCount, mentionCount }); } function showUnreadBadgeLinux(unreadCount, mentionCount) { if (remote.app.isUnityRunning()) { remote.app.setBadgeCount(mentionCount); } ipcRenderer.send('update-unread', { unreadCount, mentionCount }); } function showUnreadBadge(unreadCount, mentionCount) { switch (process.platform) { case 'win32': showUnreadBadgeWindows(unreadCount, mentionCount); break; case 'darwin': showUnreadBadgeOSX(unreadCount, mentionCount); break; case 'linux': showUnreadBadgeLinux(unreadCount, mentionCount); break; default: } } ReactDOM.render( , document.getElementById('content') );