66'use strict'
77
88import React from 'react'
9- import { Checkbox , Input , Radio , Select } from 'antd'
9+ import R from 'ramda'
10+ import { Checkbox , Input , Radio , Select , Tabs } from 'antd'
1011import MyFrame from './frame'
1112import classnames from 'classnames'
1213import Agent from '../Agent'
@@ -16,7 +17,8 @@ import './preferences.less'
1617
1718const RadioGroup = Radio . Group
1819const Option = Select . Option
19- const pref_keys = [ 'after_cmd' , 'auto_launch' , 'choice_mode' , 'hide_at_launch' , 'is_dock_icon_hidden' , 'user_language' ]
20+ const TabPane = Tabs . TabPane
21+ const pref_keys = [ 'after_cmd' , 'auto_launch' , 'choice_mode' , 'hide_at_launch' , 'is_dock_icon_hidden' , 'user_language' , 'send_usage_data' ]
2022
2123export default class PreferencesPrompt extends React . Component {
2224 constructor ( props ) {
@@ -30,6 +32,7 @@ export default class PreferencesPrompt extends React.Component {
3032 auto_launch : false ,
3133 hide_at_launch : false ,
3234 lang_list : [ ] ,
35+ send_usage_data : true ,
3336 update_found : false // 发现新版本
3437 }
3538
@@ -58,13 +61,7 @@ export default class PreferencesPrompt extends React.Component {
5861 this . setState ( {
5962 show : false
6063 } , ( ) => {
61- let prefs = { }
62- let d = this . state
63- pref_keys . map ( k => {
64- if ( d . hasOwnProperty ( k ) ) {
65- prefs [ k ] = d [ k ]
66- }
67- } )
64+ let prefs = R . pick ( pref_keys , this . state )
6865
6966 Agent . pact ( 'setPref' , prefs )
7067 . then ( ( ) => {
@@ -124,16 +121,15 @@ export default class PreferencesPrompt extends React.Component {
124121
125122 return (
126123 < div className = "ln" >
127- < div className = "title" > { lang . language } </ div >
128- < div className = "cnt" >
124+ < div > { lang . language } </ div >
125+ < div className = "inform" > { lang . should_restart_after_change_language } </ div >
126+ < div >
129127 < Select
130128 value = { this . state . user_language || '' }
131129 onChange = { v => this . updateLangKey ( v ) }
132130 >
133131 { this . getLanguageOptions ( ) }
134132 </ Select >
135-
136- < div className = "inform" > { lang . should_restart_after_change_language } </ div >
137133 </ div >
138134 </ div >
139135 )
@@ -144,8 +140,8 @@ export default class PreferencesPrompt extends React.Component {
144140
145141 return (
146142 < div className = "ln" >
147- < div className = "title" > { lang . pref_choice_mode } </ div >
148- < div className = "cnt" >
143+ < div > { lang . pref_choice_mode } </ div >
144+ < div >
149145 < RadioGroup
150146 onChange = { e => this . updateChoiceMode ( e . target . value ) }
151147 value = { this . state . choice_mode }
@@ -163,12 +159,12 @@ export default class PreferencesPrompt extends React.Component {
163159
164160 return (
165161 < div className = "ln" >
166- < div className = "title" > { lang . pref_after_cmd } </ div >
167- < div className = "cnt" >
162+ < div > { lang . pref_after_cmd } </ div >
163+ < div >
168164 < div className = "inform" > { lang . pref_after_cmd_info } </ div >
169165 < Input
170166 type = "textarea"
171- rows = { 4 }
167+ rows = { 8 }
172168 defaultValue = { this . state . after_cmd }
173169 placeholder = { lang . pref_after_cmd_placeholder }
174170 onChange = { ( e ) => this . updateAfterCmd ( e . target . value ) }
@@ -183,13 +179,12 @@ export default class PreferencesPrompt extends React.Component {
183179
184180 return (
185181 < div className = "ln" >
186- < div className = "title" > { lang . auto_launch } </ div >
187- < div className = "cnt" >
188- < Checkbox
189- value = { this . state . auto_launch }
190- onChange = { ( e ) => this . updateAutoLaunch ( e . target . checked ) }
191- />
192- </ div >
182+ < Checkbox
183+ value = { this . state . auto_launch }
184+ onChange = { ( e ) => this . updateAutoLaunch ( e . target . checked ) }
185+ >
186+ { lang . auto_launch }
187+ </ Checkbox >
193188 </ div >
194189 )
195190 }
@@ -199,12 +194,30 @@ export default class PreferencesPrompt extends React.Component {
199194
200195 return (
201196 < div className = "ln" >
202- < div className = "title" > { lang . hide_at_launch } </ div >
203- < div className = "cnt" >
197+ < Checkbox
198+ checked = { this . state . hide_at_launch }
199+ onChange = { ( e ) => this . updateMinimizeAtLaunch ( e . target . checked ) }
200+ >
201+ { lang . hide_at_launch }
202+ </ Checkbox >
203+ </ div >
204+ )
205+ }
206+
207+ prefAdvanced ( ) {
208+ let { lang} = this . props
209+
210+ return (
211+ < div className = "ln" >
212+ < div > { lang . pref_tab_usage_data_title } </ div >
213+ < div className = "inform" > { lang . pref_tab_usage_data_desc } </ div >
214+ < div >
204215 < Checkbox
205- checked = { this . state . hide_at_launch }
206- onChange = { ( e ) => this . updateMinimizeAtLaunch ( e . target . checked ) }
207- />
216+ checked = { this . state . send_usage_data }
217+ onChange = { ( e ) => this . setState ( { send_usage_data : e . target . checked } ) }
218+ >
219+ { lang . pref_tab_usage_data_label }
220+ </ Checkbox >
208221 </ div >
209222 </ div >
210223 )
@@ -215,21 +228,39 @@ export default class PreferencesPrompt extends React.Component {
215228 }
216229
217230 body ( ) {
231+ let { lang} = this . props
232+
218233 return (
219234 < div ref = "body" >
220235 { /*<div className="title">{SH_Agent.lang.hosts_title}</div>*/ }
221236 { /*<div className="cnt">*/ }
222237 { /*</div>*/ }
223238 < div
224- className = { classnames ( 'current-version' , { 'update-found' : this . state . update_found } ) } >
225- < a href = "#"
226- onClick = { PreferencesPrompt . openDownloadPage } > { formatVersion ( current_version ) } </ a >
239+ className = { classnames ( 'current-version' , { 'update-found' : this . state . update_found } ) }
240+ >
241+ < a
242+ href = "#"
243+ onClick = { PreferencesPrompt . openDownloadPage }
244+ > { formatVersion ( current_version ) } </ a >
227245 </ div >
228- { this . prefLanguage ( ) }
229- { this . prefChoiceMode ( ) }
230- { this . prefAfterCmd ( ) }
231- { /*{this.prefAutoLaunch()}*/ }
232- { this . prefMinimizeAtLaunch ( ) }
246+ < Tabs
247+ defaultActiveKey = "1"
248+ tabPosition = "left"
249+ style = { { minHeight : 240 } }
250+ >
251+ < TabPane tab = { lang . pref_tab_general } key = "1" >
252+ { this . prefLanguage ( ) }
253+ { this . prefChoiceMode ( ) }
254+ { /*{this.prefAutoLaunch()}*/ }
255+ { this . prefMinimizeAtLaunch ( ) }
256+ </ TabPane >
257+ < TabPane tab = { lang . pref_tab_custom_cmd } key = "2" >
258+ { this . prefAfterCmd ( ) }
259+ </ TabPane >
260+ < TabPane tab = { lang . pref_tab_advanced } key = "3" >
261+ { this . prefAdvanced ( ) }
262+ </ TabPane >
263+ </ Tabs >
233264 </ div >
234265 )
235266 }
0 commit comments