/** * @author oldj * @blog http://oldj.net */ 'use strict' import React from 'react' import R from 'ramda' import { Checkbox, Input, Radio, Select, Tabs } from 'antd' import MyFrame from './MyFrame' import classnames from 'classnames' import Agent from '../Agent' import { version as current_version } from '../../app/version' import formatVersion from '../../app/libs/formatVersion' import CodeMirror from 'react-codemirror' import 'codemirror/mode/shell/shell' import './PreferencesPrompt.less' const RadioGroup = Radio.Group const Option = Select.Option const TabPane = Tabs.TabPane const pref_keys = ['after_cmd', 'auto_launch', 'choice_mode', 'hide_at_launch', 'is_dock_icon_hidden', 'user_language', 'send_usage_data'] export default class PreferencesPrompt extends React.Component { constructor (props) { super(props) this.state = { show: false, user_language: '', after_cmd: '', choice_mode: 'multiple', auto_launch: false, hide_at_launch: false, lang_list: [], send_usage_data: true, update_found: false // 发现新版本 } Agent.pact('getLangList') .then(lang_list => this.setState({lang_list})) } componentDidMount () { Agent.on('show_preferences', () => { Agent.pact('getPref') .then(pref => { this.setState(Object.assign({}, pref, {show: true})) console.log(pref) }) }) Agent.on('update_found', (v) => { console.log(v) this.setState({ update_found: true }) }) } onOK () { this.setState({ show: false }, () => { let prefs = R.pick(pref_keys, this.state) Agent.pact('setPref', prefs) .then(() => { setTimeout(() => { Agent.pact('relaunch') }, 200) }) }) } onCancel () { this.setState({ show: false }) } getLanguageOptions () { return this.state.lang_list.map(({key, name}, idx) => { return ( ) }) } updateLangKey (v) { this.setState({user_language: v}) } updateChoiceMode (v) { this.setState({ choice_mode: v }) } updateAfterCmd (v) { this.setState({ after_cmd: v }) } updateAutoLaunch (v) { this.setState({ auto_launch: v }) // todo set auto launch } updateMinimizeAtLaunch (v) { this.setState({ hide_at_launch: v }) } prefLanguage () { let {lang} = this.props return (