This repository has been archived by the owner on Jun 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Preferences.react.js
170 lines (164 loc) · 5.67 KB
/
Preferences.react.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React from 'react/addons';
import metrics from '../utils/MetricsUtil';
import Router from 'react-router';
import util from '../utils/Util';
import electron from 'electron';
const remote = electron.remote;
var Preferences = React.createClass({
mixins: [Router.Navigation],
getInitialState: function () {
return {
closeVMOnQuit: localStorage.getItem('settings.closeVMOnQuit') === 'true',
useVM: localStorage.getItem('settings.useVM') === 'true',
metricsEnabled: metrics.enabled(),
terminalShell: localStorage.getItem('settings.terminalShell') || "sh",
terminalPath: localStorage.getItem('settings.terminalPath') || "/usr/bin/xterm",
startLinkedContainers: localStorage.getItem('settings.startLinkedContainers') === 'true'
};
},
handleGoBackClick: function () {
this.goBack();
metrics.track('Went Back From Preferences');
},
handleChangeCloseVMOnQuit: function (e) {
var checked = e.target.checked;
this.setState({
closeVMOnQuit: checked
});
localStorage.setItem('settings.closeVMOnQuit', checked);
metrics.track('Toggled Close VM On Quit', {
close: checked
});
},
handleChangeUseVM: function (e) {
var checked = e.target.checked;
this.setState({
useVM: checked
});
localStorage.setItem('settings.useVM', checked);
util.isNative();
metrics.track('Toggled VM or Native settting', {
vm: checked
});
},
handleChangeMetricsEnabled: function (e) {
var checked = e.target.checked;
this.setState({
metricsEnabled: checked
});
metrics.setEnabled(checked);
metrics.track('Toggled util/MetricsUtil', {
enabled: checked
});
},
handleChangeTerminalShell: function (e) {
var value = e.target.value;
this.setState({
terminalShell: value
});
localStorage.setItem('settings.terminalShell', value);
},
handleChangeTerminalPath: function (e) {
var value = e.target.value;
this.setState({
terminalPath: value
});
localStorage.setItem('settings.terminalPath', value);
},
handleChangeStartLinkedContainers: function (e) {
var checked = e.target.checked;
this.setState({
startLinkedContainers: checked
});
localStorage.setItem('settings.startLinkedContainers', checked ? 'true' : 'false');
},
render: function () {
var vmSettings, vmShutdown, nativeSetting, linuxSettings;
if (process.platform !== 'linux') {
// We are on a Mac or Windows
if (util.isNative() || (localStorage.getItem('settings.useVM') === 'true')) {
nativeSetting = (
<div className="option">
<div className="option-name">
<label htmlFor="useVM">Use VirtualBox instead of Native on next restart</label>
</div>
<div className="option-value">
<input id="useVM" type="checkbox" checked={this.state.useVM} onChange={this.handleChangeUseVM}/>
</div>
</div>
);
}
if (!util.isNative()) {
vmShutdown = (
<div className="option">
<div className="option-name">
<label htmlFor="closeVMOnQuit">Shutdown Linux VM on closing Kitematic</label>
</div>
<div className="option-value">
<input id="closeVMOnQuit" type="checkbox" checked={this.state.closeVMOnQuit} onChange={this.handleChangeCloseVMOnQuit}/>
</div>
</div>
);
}
vmSettings = (
<div>
<div className="title">VM Settings</div>
{vmShutdown}
{nativeSetting}
</div>
);
}
if (process.platform === "linux") {
linuxSettings = (
<div>
<div className="option">
<div className="option-name">
<label htmlFor="terminalPath">Terminal path</label>
</div>
<div className="option-value">
<input id="terminalPath" type="text" value={this.state.terminalPath} onChange={this.handleChangeTerminalPath}/>
</div>
</div>
</div>
)
}
return (
<div className="preferences">
<div className="preferences-content">
<a onClick={this.handleGoBackClick}>Go Back</a>
{vmSettings}
<div className="title">App Settings</div>
<div className="option">
<div className="option-name">
<label htmlFor="metricsEnabled">Report anonymous usage analytics</label>
</div>
<div className="option-value">
<input id="metricsEnabled" type="checkbox" checked={this.state.metricsEnabled} onChange={this.handleChangeMetricsEnabled}/>
</div>
</div>
<div className="option">
<div className="option-name">
<label htmlFor="terminalShell">Exec command shell</label>
</div>
<div className="option-value">
<select id="terminalShell" value={this.state.terminalShell} onChange={this.handleChangeTerminalShell}>
<option value="sh">sh</option>
<option value="bash">bash</option>
</select>
</div>
</div>
<div className="option">
<div className="option-name">
<label htmlFor="startLinkedContainers">Start linked containers</label>
</div>
<div className="option-value">
<input id="startLinkedContainers" type="checkbox" checked={this.state.startLinkedContainers} onChange={this.handleChangeStartLinkedContainers}/>
</div>
</div>
{linuxSettings}
</div>
</div>
);
}
});
module.exports = Preferences;