-
Notifications
You must be signed in to change notification settings - Fork 543
Expand file tree
/
Copy pathSettings.tsx
More file actions
572 lines (522 loc) · 17.7 KB
/
Settings.tsx
File metadata and controls
572 lines (522 loc) · 17.7 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
import {
Button,
Checkbox,
Code,
Divider,
FormLabel,
Grid,
HStack,
Heading,
Icon,
Link,
Radio,
RadioGroup,
Select,
Switch,
Tab,
TabList,
TabPanel,
TabPanels,
Tabs,
Text,
VStack,
useColorMode,
} from "@chakra-ui/react"
import { compareVersions } from "compare-versions"
import { ReactNode, useEffect, useMemo, useState } from "react"
import { HiMagnifyingGlassPlus } from "react-icons/hi2"
import { client } from "../../client"
import { ToolbarTitle, useInstallCLI } from "../../components"
import { TSettings, useChangeSettings } from "../../contexts"
import {
getIDEDisplayName,
isMacOS,
useArch,
usePlatform,
useReleases,
useUpdate,
useVersion,
} from "../../lib"
import { useWelcomeModal } from "../../useWelcomeModal"
import {
useAgentURLOption,
useDockerCredentialsForwardingOption,
useGitCredentialsForwardingOption,
useTelemetryOption,
} from "./useContextOptions"
import { useIDESettings } from "./useIDESettings"
import {
useCLIFlagsOption,
useDotfilesOption,
useExtraEnvVarsOption,
useProxyOptions,
useSSHKeySignatureOption,
} from "./useSettingsOptions"
const SETTINGS_TABS = [
{ label: "General", component: <GeneralSettings /> },
{ label: "Customization", component: <CustomizationSettings /> },
{ label: "Appearance", component: <AppearanceSettings /> },
{ label: "Updates", component: <UpdateSettings /> },
{ label: "Experimental", component: <ExperimentalSettings /> },
]
export function Settings() {
return (
<>
<ToolbarTitle>
<Heading as="h3" size="sm">
Settings
</Heading>
</ToolbarTitle>
<Tabs isLazy isFitted variant="muted">
<TabList marginBottom="6">
{SETTINGS_TABS.map(({ label }) => (
<Tab key={label}>{label}</Tab>
))}
</TabList>
<TabPanels>
{SETTINGS_TABS.map(({ label, component }) => (
<TabPanel key={label}>{component}</TabPanel>
))}
</TabPanels>
</Tabs>
</>
)
}
function GeneralSettings() {
const { settings, set } = useChangeSettings()
const { modal: welcomeModal, show: showWelcomeModal } = useWelcomeModal()
const { input: agentURLInput, helpText: agentURLHelpText } = useAgentURLOption()
const { input: proxyInput, helpText: proxyHelpText } = useProxyOptions()
const { input: telemetryInput, helpText: telemetryHelpText } = useTelemetryOption()
const {
badge: installCLIBadge,
button: installCLIButton,
helpText: installCLIHelpText,
errorMessage: installCLIErrorMessage,
} = useInstallCLI()
return (
<>
<SettingSection title="CLI" description={installCLIHelpText}>
<HStack>
{installCLIButton}
{installCLIErrorMessage}
{installCLIBadge}
</HStack>
</SettingSection>
<SettingSection
title="Debug mode"
description={
<>
Run all DevPod commands with the <Code>--debug</Code> flag, making it easier to
troubleshoot
</>
}>
<Switch
isChecked={settings.debugFlag}
onChange={(e) => set("debugFlag", e.target.checked)}
/>
</SettingSection>
<SettingSection title="Logs" description={"Open the logs for DevPod Desktop"}>
<Button variant="outline" onClick={() => client.openDir("AppLog")}>
Open Logs
</Button>
</SettingSection>
<SettingSection title="Agent URL" description={agentURLHelpText}>
{agentURLInput}
</SettingSection>
<SettingSection title="Proxy Configuration" description={proxyHelpText}>
{proxyInput}
</SettingSection>
<SettingSection title="Telemetry" description={telemetryHelpText}>
{telemetryInput}
</SettingSection>
<SettingSection
showDivider={false}
title="Show Intro"
description="Show the introduction to DevPod again">
<Button variant="outline" onClick={() => showWelcomeModal({ cancellable: true })}>
Open
</Button>
</SettingSection>
<VStack align="start" paddingTop="16" paddingBottom="8">
<Heading size="sm" as="h4" color="red.600">
Danger Zone
</Heading>
<Button variant="outline" colorScheme="red" onClick={() => client.quit()}>
Quit DevPod
</Button>
</VStack>
{welcomeModal}
</>
)
}
function CustomizationSettings() {
const { input: dotfilesInput } = useDotfilesOption()
const { input: gitSSHSignatureInput } = useSSHKeySignatureOption()
const { settings, set } = useChangeSettings()
const { ides, defaultIDE, updateDefaultIDE } = useIDESettings()
const { input: dockerCredentialForwardingInput, helpText: dockerCredentialForwardingHelpText } =
useDockerCredentialsForwardingOption()
const { input: gitCredentialForwardingInput, helpText: gitCredentialForwardingHelpText } =
useGitCredentialsForwardingOption()
return (
<>
<SettingSection
title="IDE"
description="Select the default IDE you're using for workspaces. This will be overridden whenever you create a workspace with a different IDE. You can prevent this by checking the 'Always use this IDE' checkbox">
<>
<Select
maxWidth="52"
textTransform="capitalize"
onChange={(e) => updateDefaultIDE({ ide: e.target.value })}
value={defaultIDE ? defaultIDE.name! : undefined}>
{ides?.map((ide) => (
<option key={ide.name} value={ide.name!}>
{getIDEDisplayName(ide)}
</option>
))}
</Select>
<Checkbox
isChecked={settings.fixedIDE}
onChange={(e) => set("fixedIDE", e.target.checked)}>
Always use this IDE
</Checkbox>
</>
</SettingSection>
<SettingSection
title="Dotfiles"
description="Set the dotfiles git repository to use inside workspaces">
{dotfilesInput}
</SettingSection>
<SettingSection
title="SSH Key for Git commit signing"
description="Set path of your SSH key you want to use for signing Git commits">
{gitSSHSignatureInput}
</SettingSection>
<SettingSection
title="Docker credentials forwarding"
description={dockerCredentialForwardingHelpText}>
{dockerCredentialForwardingInput}
</SettingSection>
<SettingSection
showDivider={false}
title="Git credentials forwarding"
description={gitCredentialForwardingHelpText}>
{gitCredentialForwardingInput}
</SettingSection>
</>
)
}
function AppearanceSettings() {
const { settings, set } = useChangeSettings()
return (
<>
{isMacOS && (
<SettingSection
title="Translucent UI"
description="Use transparency in the sidebar and other UI elements">
<Switch
isChecked={settings.transparency}
onChange={(e) => set("transparency", e.target.checked)}
/>
</SettingSection>
)}
<SettingSection title="Zoom level" description="Adjust the zoom level">
<HStack>
<Select
onChange={(e) => set("zoom", e.target.value as TSettings["zoom"])}
value={settings.zoom}>
<option value={"sm"}>Small</option>
<option value={"md"}>Regular</option>
<option value={"lg"}>Large</option>
<option value={"xl"}>Extra Large</option>
</Select>
<Icon as={HiMagnifyingGlassPlus} boxSize="6" color="gray.600" />
</HStack>
</SettingSection>
<SettingSection showDivider={false} title="Sidebar position" description="">
<RadioGroup
value={settings.sidebarPosition}
onChange={(newValue: TSettings["sidebarPosition"]) => set("sidebarPosition", newValue)}>
<HStack>
<Radio value="left">Left</Radio>
<Radio value="right">Right</Radio>
</HStack>
</RadioGroup>
</SettingSection>
</>
)
}
function UpdateSettings() {
const { settings, set } = useChangeSettings()
const platform = usePlatform()
const arch = useArch()
const version = useVersion()
const [selectedVersion, setSelectedVersion] = useState<string | undefined>(undefined)
const { isChecking, check, isUpdateAvailable, pendingUpdate } = useUpdate()
const releases = useReleases()
?.slice()
.sort((a, b) => compareVersions(b.tag_name, a.tag_name))
const downloadLink = useMemo(() => {
const release = releases?.find((release) => release.tag_name === selectedVersion)
if (!release) {
return undefined
}
if (!platform || !arch) {
return release.html_url
}
let p: string = platform
if (p === "darwin") {
p = "macos"
}
const r = new RegExp(`${p}_${arch}`, "i")
const asset = release.assets.find((asset) => r.test(asset.name))
return asset?.browser_download_url
}, [arch, platform, releases, selectedVersion])
useEffect(() => {
if (version) {
setSelectedVersion(`v${version}`)
}
}, [version])
const updateAvailableMessage = useMemo<undefined | string>(() => {
if (isUpdateAvailable === undefined && pendingUpdate === undefined) {
return undefined
}
return isUpdateAvailable || pendingUpdate !== undefined
? "New version available"
: "No new version"
}, [isUpdateAvailable, pendingUpdate])
return (
<>
<SettingSection
title="Automatically keep up to date"
description="Download and install new versions in the background">
<Switch
isChecked={settings.autoUpdate}
onChange={(e) => set("autoUpdate", e.target.checked)}
/>
</SettingSection>
<SettingSection
title="Versions"
description="Manage and explore DevPod versions"
showDivider={false}>
<>
<VStack align="start" width="full" marginBottom="4">
<Text fontSize="sm">
Current version: {version}
<Text as="span" fontWeight="semibold">
{updateAvailableMessage !== undefined ? ` - ${updateAvailableMessage}` : ""}
</Text>
</Text>
<HStack>
<Button variant="outline" isLoading={isChecking} onClick={() => check()}>
Check for updates
</Button>
</HStack>
</VStack>
<Text fontSize="sm">Or download a specific version</Text>
<VStack align="start" width="full" overflow="hidden">
<Select
maxWidth="52"
onChange={(e) => setSelectedVersion(e.target.value)}
value={selectedVersion}>
<option value={undefined}>Select version</option>
{releases?.map((release) => (
<option key={release.tag_name} value={release.tag_name}>
{release.tag_name}
</option>
))}
</Select>
{downloadLink && (
<Text fontSize="sm" width="full">
Visit{" "}
<Link onClick={() => client.open(downloadLink)} fontSize="sm">
Github
</Link>{" "}
to download {selectedVersion}
</Text>
)}
</VStack>
</>
</SettingSection>
</>
)
}
function ExperimentalSettings() {
const { input: cliFlagsInput, helpText: cliFlagsHelpText } = useCLIFlagsOption()
const { input: extraEnvVarsInput, helpText: extraEnvVarsHelpText } = useExtraEnvVarsOption()
const { settings, set } = useChangeSettings()
const { setColorMode } = useColorMode()
return (
<VStack align="start">
<SettingSection
title="Multiple devcontainer detection"
description="Whenever new workspaces are created, check if there are multiple devcontainers in the source. This might take a while for larger repositories">
<Switch
id="multicontainer"
isChecked={settings.experimental_multiDevcontainer}
onChange={(e) => set("experimental_multiDevcontainer", e.target.checked)}
/>
</SettingSection>
<SettingSection
title="Experimental IDEs"
description=" Enable experimental IDEs. These IDEs are not officially supported by DevPod and might be unstable. We are working on making them generally available">
<HStack>
<Switch
isChecked={settings.experimental_fleet}
onChange={(e) => set("experimental_fleet", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
JetBrains Fleet
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_jupyterNotebooks}
onChange={(e) => set("experimental_jupyterNotebooks", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
Jupyter Notebooks
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_vscodeInsiders}
onChange={(e) => set("experimental_vscodeInsiders", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
VSCode Insiders
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_cursor}
onChange={(e) => set("experimental_cursor", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
Cursor
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_positron}
onChange={(e) => set("experimental_positron", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
Positron
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_codium}
onChange={(e) => set("experimental_codium", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
Codium
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_zed}
onChange={(e) => set("experimental_zed", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
Zed
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_rstudio}
onChange={(e) => set("experimental_rstudio", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
RStudio Server
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_windsurf}
onChange={(e) => set("experimental_windsurf", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
Windsurf
</FormLabel>
</HStack>
<HStack width="full" align="center">
<Switch
isChecked={settings.experimental_antigravity}
onChange={(e) => set("experimental_antigravity", e.target.checked)}
/>
<FormLabel marginBottom="0" whiteSpace="nowrap" fontSize="sm">
Antigravity
</FormLabel>
</HStack>
</SettingSection>
<SettingSection title="Additional CLI Flags" description={cliFlagsHelpText}>
{cliFlagsInput}
</SettingSection>
<SettingSection title="Additional Environment Variables" description={extraEnvVarsHelpText}>
{extraEnvVarsInput}
</SettingSection>
<SettingSection title="DevPod Pro (beta)" description="Enable DevPod Pro login and creation">
<Switch
isChecked={settings.experimental_devPodPro}
onChange={(e) => set("experimental_devPodPro", e.target.checked)}
/>
</SettingSection>
<SettingSection title="Color Mode" description="" showDivider={false}>
<RadioGroup
value={settings.experimental_colorMode}
onChange={(newValue: TSettings["experimental_colorMode"]) => {
set("experimental_colorMode", newValue)
setColorMode(newValue)
}}>
<HStack>
<Radio value="light">Light</Radio>
<Radio value="dark">Dark</Radio>
</HStack>
</RadioGroup>
</SettingSection>
</VStack>
)
}
type TSettingDescriptionProps = Readonly<{ children: ReactNode }>
function SettingDescription({ children }: TSettingDescriptionProps) {
return (
<Text color={"gray.600"} _dark={{ color: "gray.300" }} fontSize="sm">
{children}
</Text>
)
}
type TSettingSectionProps = Readonly<{
title: string
description: ReactNode
showDivider?: boolean
children: ReactNode
}>
function SettingSection({
title,
description,
showDivider = true,
children,
}: TSettingSectionProps) {
return (
<>
<Grid gridTemplateColumns="32rem 1fr" columnGap="20" width="full">
<VStack align="start" gap="0">
<Heading as="h4" size="sm" fontWeight="medium">
{title}
</Heading>
<SettingDescription>{description}</SettingDescription>
</VStack>
<VStack align="start" paddingX="2" width="full" overflow="hidden">
{children}
</VStack>
</Grid>
{showDivider && <SettingDivider />}
</>
)
}
function SettingDivider() {
return <Divider marginY="4" />
}