This repository was archived by the owner on Jul 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathPreferences.react.js
More file actions
210 lines (203 loc) · 6.91 KB
/
Preferences.react.js
File metadata and controls
210 lines (203 loc) · 6.91 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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 FontSelect = React.createClass({
getFontSizes: function(start, end){
let options = [];
for(let i = start; i<=end; i++){
options.push(<option key={i} value={i}>{i+' px'}</option>);
}
return options;
},
render: function(){
return (
<select id={this.props.id} value={this.props.fontSize} onChange={this.props.onChange}>
{this.getFontSizes(10, 30)}
</select>
);
}
});
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',
logsFontSize: localStorage.getItem('settings.logsFontSize') || 10
};
},
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');
},
handleChangeLogsFontSize: function (e) {
var fontSize = event.target.value;
this.setState({
logsFontSize: fontSize
});
localStorage.setItem('settings.logsFontSize', fontSize);
},
getFontSizes: function(start, end){
let options = [];
for(let i = start; i<=end; i++){
options.push(<option key={i} value={i}>{i+' px'}</option>);
}
return options;
},
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>
<div className="option">
<div className="option-name">
<label htmlFor="logsFontSize">Container logs font size</label>
</div>
<div className="option-value">
<FontSelect id="logsFontSize" fontSize={this.state.logsFontSize} onChange={this.handleChangeLogsFontSize} />
</div>
</div>
{linuxSettings}
</div>
</div>
);
}
});
module.exports = Preferences;