-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
72 lines (59 loc) · 2.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React , {Component}from 'react'
import ReactDom from 'react-dom'
import TextField from 'material-ui/lib/text-field'
import Checkbox from 'material-ui/lib/checkbox'
import FlatButton from 'material-ui/lib/flat-button';
import Divider from 'material-ui/lib/divider';
import injectTapEventPlugin from 'react-tap-event-plugin'
//import {ipcRenderer} from 'electron'
const ipcRenderer = require('electron').ipcRenderer;
import './preference.css'
injectTapEventPlugin()
class Preference extends Component {
constructor() {
super()
this.state = {setting:{}}
}
componentWillMount() {
ipcRenderer.send('request-preference')
ipcRenderer.on('request-preference-reply', (event, arg)=> {
var setting = JSON.parse(arg)
this.setState({setting: {autoStartup: setting.autoStartup, shortcut: setting.shortcut}})
//this.shortcutInput.setValue(setting.shortcut)
//this.startupCheckbox.setChecked(setting.autoStartup)
});
}
handleCancel() {
ipcRenderer.send('cancel-preference')
}
handleSave() {
var newSetting = {autoStartup: this.startupCheckbox.isChecked(), shortcut: this.shortcutInput.getValue()};
this.setState({setting: newSetting});
ipcRenderer.send('save-preference', JSON.stringify(newSetting))
}
handleShortcutChange(e){
this.setState({setting:{autoStartup:this.state.setting.autoStartup, shortcut:e.target.value}})
}
handleStartupChange(e, checked){
this.setState({setting:{autoStartup:checked, shortcut:this.state.setting.shortcut}})
}
render() {
return (
<div>
<div className="setting-grp">
<Checkbox ref={(ref)=>this.startupCheckbox = ref} checked={this.state.setting.autoStartup}
onCheck={(e, checked)=>this.handleStartupChange(e,checked)}
label="Lanuch Devdocs at login"/>
<TextField ref={(ref)=>this.shortcutInput = ref} onChange={(e)=>this.handleShortcutChange(e)}
hintText="e.g. ctrl+esc, alt+s" value={this.state.setting.shortcut}
floatingLabelText="Global search shortcut"/>
</div>
<div className="btn-grp">
<FlatButton label="cancel" onClick={(e)=>this.handleCancel()}/>
<FlatButton label="Save" secondary={true} onClick={(e)=>this.handleSave()}/>
</div>
</div>
)
}
}
ReactDom.render(<Preference/>, document.getElementById('root'))