-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
appConfigSchema.ts
219 lines (208 loc) · 6.99 KB
/
appConfigSchema.ts
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
211
212
213
214
215
216
217
218
219
/**
* Copyright 2023 Gravitational, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { z } from 'zod';
import { Platform } from 'teleterm/mainProcess/types';
import { createKeyboardShortcutSchema } from './keyboardShortcutSchema';
export type AppConfigSchema = ReturnType<typeof createAppConfigSchema>;
export type AppConfig = z.infer<AppConfigSchema>;
export const createAppConfigSchema = (platform: Platform) => {
const defaultKeymap = getDefaultKeymap(platform);
const defaultTerminalFont = getDefaultTerminalFont(platform);
const shortcutSchema = createKeyboardShortcutSchema(platform);
// `keymap.` prefix is used in `initUi.ts` in a predicate function.
return z.object({
'usageReporting.enabled': z
.boolean()
.default(false)
.describe('Enables collecting of anonymous usage data.'),
'keymap.tab1': shortcutSchema
.default(defaultKeymap['tab1'])
.describe(getShortcutDesc('open tab 1')),
'keymap.tab2': shortcutSchema
.default(defaultKeymap['tab2'])
.describe(getShortcutDesc('open tab 2')),
'keymap.tab3': shortcutSchema
.default(defaultKeymap['tab3'])
.describe(getShortcutDesc('open tab 3')),
'keymap.tab4': shortcutSchema
.default(defaultKeymap['tab4'])
.describe(getShortcutDesc('open tab 4')),
'keymap.tab5': shortcutSchema
.default(defaultKeymap['tab5'])
.describe(getShortcutDesc('open tab 5')),
'keymap.tab6': shortcutSchema
.default(defaultKeymap['tab6'])
.describe(getShortcutDesc('open tab 6')),
'keymap.tab7': shortcutSchema
.default(defaultKeymap['tab7'])
.describe(getShortcutDesc('open tab 7')),
'keymap.tab8': shortcutSchema
.default(defaultKeymap['tab8'])
.describe(getShortcutDesc('open tab 8')),
'keymap.tab9': shortcutSchema
.default(defaultKeymap['tab9'])
.describe(getShortcutDesc('open tab 9')),
'keymap.closeTab': shortcutSchema
.default(defaultKeymap['closeTab'])
.describe(getShortcutDesc('close a tab')),
'keymap.newTab': shortcutSchema
.default(defaultKeymap['newTab'])
.describe(getShortcutDesc('open a new tab')),
'keymap.newTerminalTab': shortcutSchema
.default(defaultKeymap['newTerminalTab'])
.describe(getShortcutDesc('open a new terminal tab')),
'keymap.previousTab': shortcutSchema
.default(defaultKeymap['previousTab'])
.describe(getShortcutDesc('go to the previous tab')),
'keymap.nextTab': shortcutSchema
.default(defaultKeymap['nextTab'])
.describe(getShortcutDesc('go to the next tab')),
'keymap.openConnections': shortcutSchema
.default(defaultKeymap['openConnections'])
.describe(getShortcutDesc('open the connection list')),
'keymap.openClusters': shortcutSchema
.default(defaultKeymap['openClusters'])
.describe(getShortcutDesc('open the cluster selector')),
'keymap.openProfiles': shortcutSchema
.default(defaultKeymap['openProfiles'])
.describe(getShortcutDesc('open the profile selector')),
'keymap.openSearchBar': shortcutSchema
.default(defaultKeymap['openSearchBar'])
.describe(getShortcutDesc('open the search bar')),
/**
* This value can be provided by the user and is unsanitized. This means that it cannot be directly interpolated
* in a styled component or used in CSS, as it may inject malicious CSS code.
* Before using it, sanitize it with `CSS.escape` or pass it as a `style` prop.
* Read more https://frontarm.com/james-k-nelson/how-can-i-use-css-in-js-securely/.
*/
'terminal.fontFamily': z
.string()
.default(defaultTerminalFont)
.describe('Font family for the terminal.'),
'terminal.fontSize': z
.number()
.int()
.min(1)
.max(256)
.default(15)
.describe('Font size for the terminal.'),
theme: z
.enum(['light', 'dark', 'system'])
.default('system')
.describe('Color theme for the app.'),
});
};
export type KeyboardShortcutAction =
| 'tab1'
| 'tab2'
| 'tab3'
| 'tab4'
| 'tab5'
| 'tab6'
| 'tab7'
| 'tab8'
| 'tab9'
| 'closeTab'
| 'newTab'
| 'newTerminalTab'
| 'previousTab'
| 'nextTab'
| 'openSearchBar'
| 'openConnections'
| 'openClusters'
| 'openProfiles';
const getDefaultKeymap = (
platform: Platform
): Record<KeyboardShortcutAction, string> => {
switch (platform) {
case 'win32':
return {
tab1: 'Ctrl+1',
tab2: 'Ctrl+2',
tab3: 'Ctrl+3',
tab4: 'Ctrl+4',
tab5: 'Ctrl+5',
tab6: 'Ctrl+6',
tab7: 'Ctrl+7',
tab8: 'Ctrl+8',
tab9: 'Ctrl+9',
closeTab: 'Ctrl+W',
newTab: 'Ctrl+T',
newTerminalTab: 'Ctrl+Shift+T',
previousTab: 'Ctrl+Shift+Tab',
nextTab: 'Ctrl+Tab',
openSearchBar: 'Ctrl+K',
openConnections: 'Ctrl+P',
openClusters: 'Ctrl+E',
openProfiles: 'Ctrl+I',
};
case 'linux':
return {
tab1: 'Alt+1',
tab2: 'Alt+2',
tab3: 'Alt+3',
tab4: 'Alt+4',
tab5: 'Alt+5',
tab6: 'Alt+6',
tab7: 'Alt+7',
tab8: 'Alt+8',
tab9: 'Alt+9',
closeTab: 'Ctrl+W',
newTab: 'Ctrl+T',
newTerminalTab: 'Ctrl+Shift+T',
previousTab: 'Ctrl+Shift+Tab',
nextTab: 'Ctrl+Tab',
openSearchBar: 'Ctrl+K',
openConnections: 'Ctrl+P',
openClusters: 'Ctrl+E',
openProfiles: 'Ctrl+I',
};
case 'darwin':
return {
tab1: 'Command+1',
tab2: 'Command+2',
tab3: 'Command+3',
tab4: 'Command+4',
tab5: 'Command+5',
tab6: 'Command+6',
tab7: 'Command+7',
tab8: 'Command+8',
tab9: 'Command+9',
closeTab: 'Command+W',
newTab: 'Command+T',
newTerminalTab: 'Shift+Command+T',
previousTab: 'Control+Shift+Tab',
nextTab: 'Control+Tab',
openSearchBar: 'Command+K',
openConnections: 'Command+P',
openClusters: 'Command+E',
openProfiles: 'Command+I',
};
}
};
function getDefaultTerminalFont(platform: Platform) {
switch (platform) {
case 'win32':
return 'Consolas, monospace';
case 'linux':
return "'Droid Sans Mono', monospace";
case 'darwin':
return 'Menlo, Monaco, monospace';
}
}
function getShortcutDesc(actionDesc: string): string {
return `Shortcut to ${actionDesc}. A valid shortcut contains at least one modifier and a single key code, for example "Shift+Tab". Function keys do not require a modifier.`;
}