'use strict';
window.eval = global.eval = function() {
throw new Error("Sorry, Mattermost does not support window.eval() for security reasons.");
}
const {remote, ipcRenderer} = require('electron');
const settings = require('../common/settings');
const React = require('react');
const ReactDOM = require('react-dom');
const {Grid, Row, Col, Input, Button, ListGroup, ListGroupItem, Glyphicon, HelpBlock, Navbar, Nav} = require('react-bootstrap');
var AutoLaunch = require('auto-launch');
var appLauncher = new AutoLaunch({
name: 'Mattermost'
});
function backToIndex() {
remote.getCurrentWindow().loadURL('file://' + __dirname + '/index.html');
}
var SettingsPage = React.createClass({
getInitialState: function() {
var initialState;
try {
initialState = settings.readFileSync(this.props.configFile);
} catch (e) {
initialState = settings.loadDefault();
}
initialState.showAddTeamForm = false;
initialState.trayWasVisible = remote.getCurrentWindow().trayWasVisible;
return initialState;
},
componentDidMount: function() {
if (process.platform === 'win32' || process.platform === 'linux') {
var self = this;
appLauncher.isEnabled().then(function(enabled) {
self.setState({
autostart: enabled
});
});
}
},
handleTeamsChange: function(teams) {
this.setState({
showAddTeamForm: false,
teams: teams
});
},
handleSave: function() {
var config = {
teams: this.state.teams,
hideMenuBar: this.state.hideMenuBar,
showTrayIcon: this.state.showTrayIcon,
trayIconTheme: this.state.trayIconTheme,
disablewebsecurity: this.state.disablewebsecurity,
version: settings.version,
minimizeToTray: this.state.minimizeToTray,
toggleWindowOnTrayIconClick: this.state.toggleWindowOnTrayIconClick,
notifications: {
flashWindow: this.state.notifications.flashWindow
},
showUnreadBadge: this.state.showUnreadBadge
};
settings.writeFileSync(this.props.configFile, config);
if (process.platform === 'win32' || process.platform === 'linux') {
var currentWindow = remote.getCurrentWindow();
currentWindow.setAutoHideMenuBar(config.hideMenuBar);
currentWindow.setMenuBarVisibility(!config.hideMenuBar);
var autostart = this.state.autostart;
appLauncher.isEnabled().then(function(enabled) {
if (enabled && !autostart) {
appLauncher.disable();
} else if (!enabled && autostart) {
appLauncher.enable();
}
});
}
ipcRenderer.send('update-menu', config);
ipcRenderer.send('update-config');
backToIndex();
},
handleCancel: function() {
backToIndex();
},
handleChangeDisableWebSecurity: function() {
this.setState({
disablewebsecurity: this.refs.disablewebsecurity.getChecked()
});
},
handleChangeHideMenuBar: function() {
this.setState({
hideMenuBar: this.refs.hideMenuBar.getChecked()
});
},
handleChangeShowTrayIcon: function() {
var shouldShowTrayIcon = this.refs.showTrayIcon.getChecked();
this.setState({
showTrayIcon: shouldShowTrayIcon
});
if (process.platform === 'darwin' && !shouldShowTrayIcon) {
this.setState({
minimizeToTray: false
});
}
},
handleChangeTrayIconTheme: function() {
this.setState({
trayIconTheme: this.refs.trayIconTheme.getValue()
});
},
handleChangeAutoStart: function() {
this.setState({
autostart: this.refs.autostart.getChecked()
});
},
handleChangeMinimizeToTray: function() {
var shouldMinimizeToTray = (process.platform !== 'darwin' || this.refs.showTrayIcon.getChecked())
&& this.refs.minimizeToTray.getChecked();
this.setState({
minimizeToTray: shouldMinimizeToTray
});
},
handleChangeToggleWindowOnTrayIconClick: function() {
this.setState({
toggleWindowOnTrayIconClick: this.refs.toggleWindowOnTrayIconClick.getChecked()
});
},
toggleShowTeamForm: function() {
this.setState({
showAddTeamForm: !this.state.showAddTeamForm
});
},
handleFlashWindow: function() {
this.setState({
notifications: {
flashWindow: this.refs.flashWindow.getChecked() ? 2 : 0
}
});
},
handleShowUnreadBadge: function() {
this.setState({
showUnreadBadge: this.refs.showUnreadBadge.getChecked()
});
},
render: function() {
var teams_row = (
App options
{ options }