'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, toggleWindowOnTrayIconClick: this.state.toggleWindowOnTrayIconClick, 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() { var shouldShowTrayIcon = this.refs.showTrayIcon.getChecked(); this.setState({ showTrayIcon: shouldShowTrayIcon }); }, handleChangeTrayIconTheme: function() { this.setState({ trayIconTheme: this.refs.trayIconTheme.getValue() }); }, handleChangeAutoStart: function() { this.setState({ autostart: this.refs.autostart.getChecked() }); }, handleChangeToggleWindowOnTrayIconClick: function() { this.setState({ toggleWindowOnTrayIconClick: this.refs.toggleWindowOnTrayIconClick.getChecked() }); }, toggleShowTeamForm: function() { this.setState({ showAddTeamForm: !this.state.showAddTeamForm }); }, handleFlashWindowSetting: function(item) { this.setState({ notifications: { flashWindow: item.state } }); }, render: function() { var teams_row = ( ); 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 === 'win32') { options.push(); } var options_row = (options.length > 0) ? (

Options

{ options }
) : null; var notifications_row = null; if (process.platform === 'win32') { var notificationSettings = [ { label: 'Never', state: 0 }, /* ToDo: Idle isn't implemented yet { label: 'Only when idle (after 10 seconds)', state: 1 },*/ { label: 'Always', state: 2 } ]; var that = this; var notificationElements = notificationSettings.map(function(item) { var boundClick = that.handleFlashWindowSetting.bind(that, item); return ( ); }); notifications_row = (

Notifications

Configure, that the taskicon in the taskbar blinks when new message arrives. { notificationElements }
); } return (

Teams

{ teams_row } { options_row } { notifications_row }

{ ' ' }
); } }); var TeamList = React.createClass({ getInitialState: function() { return { showTeamListItemNew: false, team: { url: '', name: '', index: false } }; }, handleTeamRemove: function(index) { console.log(index); var teams = this.props.teams; teams.splice(index, 1); this.props.onTeamsChange(teams); }, handleTeamAdd: function(team) { var teams = this.props.teams; // check if team already exists and then change existing team or add new one if ((team.index !== undefined) && teams[team.index]) { teams[team.index].name = team.name; teams[team.index].url = team.url; } else { teams.push(team); } this.setState({ showTeamListItemNew: false, team: { url: '', name: '', index: false } }); this.props.onTeamsChange(teams); }, handleTeamEditing: function(teamName, teamUrl, teamIndex) { this.setState({ showTeamListItemNew: true, team: { url: teamUrl, name: teamName, index: teamIndex } }) }, render: function() { var thisObj = this; var teamNodes = this.props.teams.map(function(team, i) { var handleTeamRemove = function() { thisObj.handleTeamRemove(i); }; var handleTeamEditing = function() { thisObj.handleTeamEditing(team.name, team.url, i); }; return ( ); }); var addTeamForm; if (this.props.showAddTeamForm || this.state.showTeamListItemNew) { addTeamForm = ; } else { addTeamForm = ''; } return ( { teamNodes } { addTeamForm } ); } }); var TeamListItem = React.createClass({ handleTeamRemove: function() { this.props.onTeamRemove(); }, handleTeamEditing: function() { this.props.onTeamEditing(); }, render: function() { var style = { left: { "display": 'inline-block' } }; return (

{ this.props.name }

{ this.props.url }

{ ' ' }
); } }); var TeamListItemNew = React.createClass({ getInitialState: function() { return { name: this.props.teamName, url: this.props.teamUrl, index: this.props.teamIndex }; }, handleSubmit: function(e) { console.log('submit'); e.preventDefault(); this.props.onTeamAdd({ name: this.state.name.trim(), url: this.state.url.trim(), index: this.state.index, }); this.setState({ name: '', url: '', index: '' }); }, handleNameChange: function(e) { console.log('name'); this.setState({ name: e.target.value }); }, handleURLChange: function(e) { console.log('url'); this.setState({ url: e.target.value }); }, shouldEnableAddButton: function() { return (this.state.name.trim() !== '' || this.props.teamName !== '') && (this.state.url.trim() !== '' || this.props.teamUrl !== ''); }, render: function() { var existingTeam = false; if (this.state.name !== '' && this.state.url !== '') { existingTeam = true; } var btnAddText; if (existingTeam) { btnAddText = 'Save'; } else { btnAddText = 'Add'; } return (
{ ' ' }
{ ' ' }
{ ' ' }
{ ' ' }
); } }); var configFile = remote.getGlobal('config-file'); var contextMenu = require('./menus/context'); var menu = contextMenu.createDefault(); window.addEventListener('contextmenu', function(e) { menu.popup(remote.getCurrentWindow()); }, false); ReactDOM.render( , document.getElementById('content') );