'use strict';
const {remote, ipcRenderer} = require('electron');
const settings = require('../common/settings');
const React = require('react');
const ReactDOM = require('react-dom');
const ReactBootstrap = require('react-bootstrap');
var AutoLaunch = require('auto-launch');
const Grid = ReactBootstrap.Grid;
const Row = ReactBootstrap.Row;
const Col = ReactBootstrap.Col;
const Input = ReactBootstrap.Input;
const Button = ReactBootstrap.Button;
const ListGroup = ReactBootstrap.ListGroup;
const ListGroupItem = ReactBootstrap.ListGroupItem;
const Glyphicon = ReactBootstrap.Glyphicon;
var appLauncher = new AutoLaunch({
name: 'Mattermost'
});
function backToIndex() {
remote.getCurrentWindow().loadURL('file://' + __dirname + '/index.html');
}
var SettingsPage = React.createClass({
getInitialState: function() {
var config;
try {
config = settings.readFileSync(this.props.configFile);
} catch (e) {
config = settings.loadDefault();
}
config.showAddTeamForm = false;
return config;
},
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({
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,
notifications: {
flashWindow: this.state.notifications.flashWindow
}
};
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() {
this.setState({
showTrayIcon: this.refs.showTrayIcon.getChecked()
});
},
handleChangeTrayIconTheme: function() {
this.setState({
trayIconTheme: this.refs.trayIconTheme.getValue()
});
},
handleChangeAutoStart: function() {
this.setState({
autostart: this.refs.autostart.getChecked()
});
},
toggleShowTeamForm: function() {
this.setState({
showAddTeamForm: !this.state.showAddTeamForm
});
},
handleFlashWindowSetting: function(item) {
this.setState({
notifications: {
flashWindow: item.state
}
});
},
render: function() {
var teams_row = (
Options
{ options }
Notifications
Configure, that the taskicon in the taskbar blinks when new message arrives.
{ notificationElements }
Teams
{ this.props.url }