import PropTypes from 'prop-types' import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './ConfigTab.styl' import ConfigManager from 'browser/main/lib/ConfigManager' import store from 'browser/main/store' import _ from 'lodash' import i18n from 'browser/lib/i18n' const electron = require('electron') const ipc = electron.ipcRenderer class HotkeyTab extends React.Component { constructor (props) { super(props) this.state = { isHotkeyHintOpen: false, config: props.config } } componentDidMount () { this.handleSettingDone = () => { this.setState({keymapAlert: { type: 'success', message: i18n.__('Successfully applied!') }}) } this.handleSettingError = (err) => { this.setState({keymapAlert: { type: 'error', message: err.message != null ? err.message : i18n.__('Error occurs!') }}) } this.oldHotkey = this.state.config.hotkey 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) } handleSaveButtonClick (e) { const newConfig = { hotkey: this.state.config.hotkey } ConfigManager.set(newConfig) store.dispatch({ type: 'SET_UI', config: newConfig }) this.clearMessage() this.props.haveToSave() } handleHintToggleButtonClick (e) { this.setState({ isHotkeyHintOpen: !this.state.isHotkeyHintOpen }) } handleHotkeyChange (e) { const { config } = this.state config.hotkey = { toggleMain: this.refs.toggleMain.value, toggleMode: this.refs.toggleMode.value } this.setState({ config }) if (_.isEqual(this.oldHotkey, config.hotkey)) { this.props.haveToSave() } else { this.props.haveToSave({ tab: 'Hotkey', type: 'warning', message: i18n.__('Unsaved Changes!') }) } } clearMessage () { _.debounce(() => { this.setState({ keymapAlert: null }) }, 2000)() } render () { const keymapAlert = this.state.keymapAlert const keymapAlertElement = keymapAlert != null ?
{keymapAlert.message}
: null const { config } = this.state return ({i18n.__('Available Keys')}
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 MediaPlayPauseControl (or Ctrl for short)Shift