Skip to content

Commit

Permalink
temp: test schema migration
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoventura committed Dec 2, 2024
1 parent 8a2e5e2 commit 5fb2026
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/components/Settings/AppearanceSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export function AppearanceSettings() {
return (
<SettingsSection>
<FieldGroup
name="appearance.theme"
name="general.appearance.theme"
label="Theme"
errors={errors}
hint="Select whether the app should use a light theme, dark theme, or match your system settings."
hintType="text"
>
<Controller
name="appearance.theme"
name="general.appearance.theme"
control={control}
render={({ field }) => (
<RadioCards.Root
Expand Down
4 changes: 2 additions & 2 deletions src/components/Settings/UsageReportSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const UsageReportSettings = () => {
<Flex gap="2">
<Controller
control={control}
name="usageReport.enabled"
name="general.usageReport.enabled"
render={({ field }) => (
<Text size="2" as="label">
<Checkbox
{...register('usageReport.enabled')}
{...register('general.usageReport.enabled')}
checked={field.value}
onCheckedChange={field.onChange}
/>{' '}
Expand Down
16 changes: 8 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ const createWindow = async () => {
app.whenReady().then(async () => {
await initSettings()
appSettings = await getSettings()
nativeTheme.themeSource = appSettings.appearance.theme
nativeTheme.themeSource = appSettings.general.appearance.theme

await sendReport(appSettings.usageReport)
await sendReport(appSettings.general.usageReport)
await createSplashWindow()
await setupProjectStructure()
await createWindow()
Expand Down Expand Up @@ -353,7 +353,7 @@ ipcMain.handle(
browserWindow,
resolvedScriptPath,
appSettings.proxy.port,
appSettings.usageReport.enabled
appSettings.general.usageReport.enabled
)
}
)
Expand Down Expand Up @@ -628,12 +628,12 @@ async function applySettings(
if (modifiedSettings.recorder) {
appSettings.recorder = modifiedSettings.recorder
}
if (modifiedSettings.usageReport) {
appSettings.usageReport = modifiedSettings.usageReport
if (modifiedSettings.general?.usageReport) {
appSettings.general.usageReport = modifiedSettings.general.usageReport
}
if (modifiedSettings.appearance) {
appSettings.appearance = modifiedSettings.appearance
nativeTheme.themeSource = appSettings.appearance.theme
if (modifiedSettings.general?.appearance) {
appSettings.general.appearance = modifiedSettings.general.appearance
nativeTheme.themeSource = appSettings.general.appearance.theme
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/schemas/settings/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ export function migrate(
proxy: settings.proxy,
recorder: settings.recorder,
windowState: settings.windowState,
usageReport: settings.usageReport,
appearance: settings.appearance,
general: {
usageReport: settings.usageReport,
appearance: settings.appearance,
},
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/schemas/settings/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export const AppSettingsSchema = z.object({
proxy: ProxySettingsSchema,
recorder: RecorderSettingsSchema,
windowState: WindowStateSchema,
usageReport: UsageReportSettingsSchema,
appearance: AppearanceSchema,
general: z.object({
usageReport: UsageReportSettingsSchema,
appearance: AppearanceSchema,
}),
})

export type AppSettings = z.infer<typeof AppSettingsSchema>
Expand Down
12 changes: 7 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const defaultSettings: AppSettings = {
y: 0,
isMaximized: true,
},
usageReport: {
enabled: true,
},
appearance: {
theme: 'system',
general: {
usageReport: {
enabled: true,
},
appearance: {
theme: 'system',
},
},
}

Expand Down

0 comments on commit 5fb2026

Please sign in to comment.