const React = require('react'); const {Col, Grid, Navbar, Input, 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; return initialState; }, componentDidMount() { if (process.platform === 'win32' || process.platform === 'linux') { var self = this; appLauncher.isEnabled().then((enabled) => { self.setState({ autostart: enabled }); }); } }, 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.getChecked() }); }, handleChangeHideMenuBar() { this.setState({ hideMenuBar: this.refs.hideMenuBar.getChecked() }); }, handleChangeShowTrayIcon() { var shouldShowTrayIcon = this.refs.showTrayIcon.getChecked(); this.setState({ showTrayIcon: shouldShowTrayIcon }); if (process.platform === 'darwin' && !shouldShowTrayIcon) { this.setState({ minimizeToTray: false }); } }, handleChangeTrayIconTheme() { this.setState({ trayIconTheme: this.refs.trayIconTheme.getValue() }); }, handleChangeAutoStart() { this.setState({ autostart: this.refs.autostart.getChecked() }); }, handleChangeMinimizeToTray() { var shouldMinimizeToTray = (process.platform !== 'darwin' || this.refs.showTrayIcon.getChecked()) && this.refs.minimizeToTray.getChecked(); this.setState({ minimizeToTray: shouldMinimizeToTray }); }, handleChangeToggleWindowOnTrayIconClick() { this.setState({ toggleWindowOnTrayIconClick: this.refs.toggleWindowOnTrayIconClick.getChecked() }); }, toggleShowTeamForm() { this.setState({ showAddTeamForm: !this.state.showAddTeamForm }); }, handleFlashWindow() { this.setState({ notifications: { flashWindow: this.refs.flashWindow.getChecked() ? 2 : 0 } }); }, handleShowUnreadBadge() { this.setState({ showUnreadBadge: this.refs.showUnreadBadge.getChecked() }); }, render() { var teamsRow = ( ); var options = []; if (process.platform === 'win32' || process.platform === 'linux') { options.push( ); } if (process.platform === 'darwin' || process.platform === 'linux') { options.push( ); } if (process.platform === 'linux') { options.push( ); } options.push( ); //OSX has an option in the Dock, to set the app to autostart, so we choose to not support this option for OSX if (process.platform === 'win32' || process.platform === 'linux') { options.push( ); } if (process.platform === 'darwin' || process.platform === 'linux') { options.push( ); } if (process.platform === 'win32') { options.push( ); } if (process.platform === 'darwin' || process.platform === 'win32') { options.push( ); } if (process.platform === 'win32' || process.platform === 'linux') { options.push( ); } const settingsPage = { navbar: { backgroundColor: '#fff' }, close: { position: 'absolute', right: '0', top: '10px', fontSize: '35px', fontWeight: 'normal', color: '#bbb', cursor: 'pointer' }, heading: { textAlign: 'center', fontSize: '24px', margin: '0', padding: '1em 0' }, sectionHeading: { fontSize: '20px', margin: '0', padding: '1em 0' }, sectionHeadingLink: { marginTop: '24px', display: 'inline-block', fontSize: '15px' }, footer: { padding: '0.4em 0' } }; var optionsRow = (options.length > 0) ? (

{'App options'}

{ options }
) : null; return (

{'Settings'}

{'×'}

{'Team Management'}

{'⊞ Add new team'}

{ teamsRow }
{ optionsRow }
{ ' ' }
); } }); module.exports = SettingsPage;