import React, { PropTypes } from 'react' import linkState from 'browser/lib/linkState' import { updateUser } from '../../actions' import fetchConfig from 'browser/lib/fetchConfig' const electron = require('electron') const ipc = electron.ipcRenderer const remote = electron.remote const OSX = global.process.platform === 'darwin' export default class AppSettingTab extends React.Component { constructor (props) { super(props) let keymap = Object.assign({}, remote.getGlobal('keymap')) let config = Object.assign({}, fetchConfig()) let userName = props.user != null ? props.user.name : null this.state = { user: { name: userName, alert: null }, userAlert: null, keymap: keymap, keymapAlert: null, config: config, configAlert: null } } componentDidMount () { this.handleSettingDone = () => { this.setState({keymapAlert: { type: 'success', message: 'Successfully done!' }}) } this.handleSettingError = err => { this.setState({keymapAlert: { type: 'error', message: err.message != null ? err.message : 'Error occurs!' }}) } ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) } componentWillUnmount () { ipc.removeListener('APP_SETTING_DONE', this.handleSettingDone) ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError) } submitHotKey () { ipc.send('hotkeyUpdated', this.state.keymap) } submitConfig () { ipc.send('configUpdated', this.state.config) } handleSaveButtonClick (e) { this.submitHotKey() } handleConfigSaveButtonClick (e) { this.submitConfig() } handleKeyDown (e) { if (e.keyCode === 13) { this.submitHotKey() } } handleConfigKeyDown (e) { if (e.keyCode === 13) { this.submitConfig() } } handleDisableDirectWriteClick (e) { let config = this.state.config config['disable-direct-write'] = !config['disable-direct-write'] this.setState({ config }) } handleNameSaveButtonClick (e) { let { dispatch } = this.props dispatch(updateUser({name: this.state.user.name})) this.setState({ userAlert: { type: 'success', message: 'Successfully done!' } }) } render () { let keymapAlert = this.state.keymapAlert let keymapAlertElement = keymapAlert != null ? (
{keymapAlert.message}
) : null let userAlert = this.state.userAlert let userAlertElement = userAlert != null ? ({userAlert.message}
) : null return (0 to 9A to ZF1 to F24~, !, @, #, $, etc.PlusSpaceBackspaceDeleteInsertReturn (or Enter as alias)Up, Down, Left and RightHome and EndPageUp and PageDownEscape (or Esc for short)VolumeUp, VolumeDown and VolumeMuteMediaNextTrack, MediaPreviousTrack, MediaStop and MediaPlayPause