Skip to content

Commit cc17b94

Browse files
committed
Merge branch 'feature/pref' into develop
2 parents 0043e35 + 79f248e commit cc17b94

File tree

9 files changed

+119
-51
lines changed

9 files changed

+119
-51
lines changed

app/lang/cn.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ exports.content = {
7878
, pref_choice_mode: '选择模式'
7979
, pref_choice_mode_multiple: '多选'
8080
, pref_choice_mode_single: '单选'
81+
, pref_tab_advanced: '高级'
82+
, pref_tab_custom_cmd: '自定义命令'
83+
, pref_tab_general: '通用'
84+
, pref_tab_usage_data_title: '帮助改进 SwitchHosts!'
85+
, pref_tab_usage_data_desc: '您愿意发送匿名的使用数据来帮助我们改进 SwitchHosts! 吗?数据中不会包含任何隐私信息。'
86+
, pref_tab_usage_data_label: '好的,发送匿名的使用数据'
8187
, preferences: '设置'
8288
, quit: '退出'
8389
, readonly: '只读'

app/lang/en.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ exports.content = {
7878
, pref_choice_mode: 'Choice mode'
7979
, pref_choice_mode_multiple: 'Multiple choices'
8080
, pref_choice_mode_single: 'Single choice'
81+
, pref_tab_advanced: 'Advanced'
82+
, pref_tab_custom_cmd: 'Custom comand'
83+
, pref_tab_general: 'General'
84+
, pref_tab_usage_data_title: 'Make SwitchHosts! better!'
85+
, pref_tab_usage_data_desc: 'Would you like to help us improve SwitchHosts! by periodically submitting anonymous usage data?'
86+
, pref_tab_usage_data_label: 'Yes, submit anonymized usage data'
8187
, preferences: 'Preferences'
8288
, quit: 'Quit'
8389
, readonly: 'Read only'

app/server/actions/statRecord.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
const request = require('request')
99
const version = require('../../configs').version_full
10+
const getPref = require('./getPref')
1011

1112
const url = 'http://lab.oldj.net/s.gif'
1213
const session_id = (new Date()).getTime() + ':' + Math.random()
1314
const queue = []
1415
let is_initialized = false
16+
let send_usage_data = null
1517

1618
function log (actions) {
1719
let u = url + '?' + [
@@ -39,13 +41,27 @@ function send () {
3941
if (queue.length === 0) return
4042

4143
let action = queue.splice(0).join(',')
42-
log(action)
44+
if (send_usage_data) {
45+
log(action)
46+
} else {
47+
console.log('send_usage_data:false')
48+
}
49+
}
50+
51+
function initGetPrefCfg () {
52+
return getPref()
53+
.then(v => v.send_usage_data)
54+
.then(v => {
55+
send_usage_data = (v !== false)
56+
})
4357
}
4458

4559
function init () {
4660
if (is_initialized) return
4761
is_initialized = true
4862

63+
initGetPrefCfg()
64+
4965
record('launch')
5066
//SH_event.on('toggle_host', () => {
5167
// record('switch')

app/ui/bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exports.version = [3,3,6,5276];
1+
exports.version = [3,3,6,5280];

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dll": "webpack --config scripts/webpack.dll.js --progress --profile --colors",
1111
"dev": "cross-env ENV=dev electron app",
1212
"build": "gulp ver && npm run _ln && webpack --progress --profile --colors",
13+
"w": "npm run build -- -w",
1314
"pack": "gulp pack",
1415
"pack-mac": "gulp pack --platform=macOS",
1516
"pack-win": "gulp pack --platform=win64",
@@ -27,7 +28,6 @@
2728
"url": "https://github.com/oldj/SwitchHosts/issues"
2829
},
2930
"homepage": "https://oldj.github.io/SwitchHosts/",
30-
"dependencies": {},
3131
"devDependencies": {
3232
"antd": "^2.10.2",
3333
"autoprefixer": "^6.7.2",
@@ -81,6 +81,7 @@
8181
"opn": "^4.0.2",
8282
"optimize-css-assets-webpack-plugin": "^1.3.0",
8383
"ora": "^1.1.0",
84+
"ramda": "^0.24.1",
8485
"react": "^15.5.4",
8586
"react-dom": "^15.5.4",
8687
"rimraf": "^2.6.0",
@@ -111,4 +112,4 @@
111112
"presets": ["latest", "stage-0"]
112113
}
113114
}
114-
}
115+
}

ui/frame/frame.less

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
line-height: @lh;
3737
padding: 2px 0;
3838
margin-bottom: 10px;
39+
white-space: normal;
3940

4041
.title {
4142
float: left;
@@ -45,19 +46,20 @@
4546
.cnt {
4647
margin-left: 100px;
4748
line-height: @lh;
48-
//input[type=text] {
49-
// width: 240px;
50-
// outline: none;
51-
// padding: 4px 10px;
52-
//}
49+
input[type=text] {
50+
width: 240px;
51+
outline: none;
52+
padding: 4px 10px;
53+
}
5354
textarea {
5455
font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;
5556
}
5657
}
5758

5859
.inform {
5960
color: #999;
60-
line-height: @lh;
61+
line-height: 20px;
62+
margin-bottom: 5px;
6163
}
6264
}
6365

ui/frame/preferences.jsx

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
'use strict'
77

88
import 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'
1011
import MyFrame from './frame'
1112
import classnames from 'classnames'
1213
import Agent from '../Agent'
@@ -16,7 +17,8 @@ import './preferences.less'
1617

1718
const RadioGroup = Radio.Group
1819
const 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

2123
export 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

Comments
 (0)