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 : '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 } this.setState({ config }) if (_.isEqual(this.oldHotkey, config.hotkey)) { this.props.haveToSave() } else { this.props.haveToSave({ tab: 'Hotkey', type: 'warning', message: i18n.__('You have to save!') }) } } 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.__('Hotkeys')}
{i18n.__('Show/Hide Boostnote')}
this.handleHotkeyChange(e)} ref='toggleMain' value={config.hotkey.toggleMain} type='text' />
{keymapAlertElement}
{this.state.isHotkeyHintOpen &&

Available Keys

  • 0 to 9
  • A to Z
  • F1 to F24
  • Punctuations like ~, !, @, #, $, etc.
  • Plus
  • Space
  • Backspace
  • Delete
  • Insert
  • Return (or Enter as alias)
  • Up, Down, Left and Right
  • Home and End
  • PageUp and PageDown
  • Escape (or Esc for short)
  • VolumeUp, VolumeDown and VolumeMute
  • MediaNextTrack, MediaPreviousTrack, MediaStop and MediaPlayPause
  • Control (or Ctrl for short)
  • Shift
}
) } } HotkeyTab.propTypes = { dispatch: PropTypes.func, haveToSave: PropTypes.func } export default CSSModules(HotkeyTab, styles)