const React = require('react');
const ReactDOM = require('react-dom');
const {Button, Checkbox, Col, FormGroup, Grid, HelpBlock, Navbar, Radio, Row} = require('react-bootstrap');
const {ipcRenderer, remote} = require('electron');
const AutoLaunch = require('auto-launch');
const settings = require('../../common/settings');
const TeamList = require('./TeamList.jsx');
const appLauncher = new AutoLaunch({
name: 'Mattermost',
isHidden: true
});
function backToIndex() {
remote.getCurrentWindow().loadURL('file://' + __dirname + '/index.html');
}
const SettingsPage = React.createClass({
propTypes: {
configFile: React.PropTypes.string
},
getInitialState() {
var initialState;
try {
initialState = settings.readFileSync(this.props.configFile);
} catch (e) {
initialState = settings.loadDefault();
}
initialState.showAddTeamForm = false;
initialState.trayWasVisible = remote.getCurrentWindow().trayWasVisible;
initialState.disableClose = initialState.teams.length === 0;
return initialState;
},
componentDidMount() {
if (process.platform === 'win32' || process.platform === 'linux') {
var self = this;
appLauncher.isEnabled().then((enabled) => {
self.setState({
autostart: enabled
});
});
}
ipcRenderer.on('add-server', () => {
this.setState({
showAddTeamForm: true
});
});
},
handleTeamsChange(teams) {
this.setState({
showAddTeamForm: false,
teams
});
},
handleSave() {
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((enabled) => {
if (enabled && !autostart) {
appLauncher.disable();
} else if (!enabled && autostart) {
appLauncher.enable();
}
});
}
ipcRenderer.send('update-menu', config);
ipcRenderer.send('update-config');
backToIndex();
},
handleCancel() {
backToIndex();
},
handleChangeDisableWebSecurity() {
this.setState({
disablewebsecurity: this.refs.disablewebsecurity.props.checked
});
},
handleChangeHideMenuBar() {
this.setState({
hideMenuBar: !this.refs.hideMenuBar.props.checked
});
},
handleChangeShowTrayIcon() {
var shouldShowTrayIcon = !this.refs.showTrayIcon.props.checked;
this.setState({
showTrayIcon: shouldShowTrayIcon
});
if (process.platform === 'darwin' && !shouldShowTrayIcon) {
this.setState({
minimizeToTray: false
});
}
},
handleChangeTrayIconTheme() {
this.setState({
trayIconTheme: ReactDOM.findDOMNode(this.refs.trayIconTheme).value
});
},
handleChangeAutoStart() {
this.setState({
autostart: !this.refs.autostart.props.checked
});
},
handleChangeMinimizeToTray() {
const shouldMinimizeToTray = this.state.showTrayIcon && !this.refs.minimizeToTray.props.checked;
this.setState({
minimizeToTray: shouldMinimizeToTray
});
},
handleChangeToggleWindowOnTrayIconClick() {
this.setState({
toggleWindowOnTrayIconClick: !this.refs.toggleWindowOnTrayIconClick.props.checked
});
},
toggleShowTeamForm() {
this.setState({
showAddTeamForm: !this.state.showAddTeamForm
});
},
setShowTeamFormVisibility(val) {
this.setState({
showAddTeamForm: val
});
},
handleFlashWindow() {
this.setState({
notifications: {
flashWindow: this.refs.flashWindow.props.checked ? 0 : 2
}
});
},
handleShowUnreadBadge() {
this.setState({
showUnreadBadge: !this.refs.showUnreadBadge.props.checked
});
},
updateTeam(index, newData) {
var teams = this.state.teams;
teams[index] = newData;
this.setState({
teams
});
},
addServer(team) {
var teams = this.state.teams;
teams.push(team);
this.setState({
teams
});
},
render() {
var teamsRow = (
{'App Options'}
{ options.map((opt, i) => (