diff --git a/apps/desktop/src/settings/DesktopAppSettings.test.ts b/apps/desktop/src/settings/DesktopAppSettings.test.ts index 0135225f90c48..93a60d2c77f76 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.test.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.test.ts @@ -170,6 +170,9 @@ describe("DesktopSettings", () => { "tailscaleServeEnabled": true, "tailscaleServePort": 8443, "mainWindowBounds": { "x": 120, "y": 80, "width": 1280, "height": 900 }, + // Values this build cannot read fall back per field, not for the whole file. + "updateChannel": "beta", + "wslOnly": "yes", }\n`, ); diff --git a/apps/desktop/src/settings/DesktopAppSettings.ts b/apps/desktop/src/settings/DesktopAppSettings.ts index a0624ced669ea..20185904516c3 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.ts @@ -14,6 +14,7 @@ import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; +import * as Struct from "effect/Struct"; import * as SynchronizedRef from "effect/SynchronizedRef"; import * as DesktopEnvironment from "../app/DesktopEnvironment.ts"; @@ -104,7 +105,21 @@ const DesktopSettingsDocument = Schema.Struct({ type DesktopSettingsDocument = typeof DesktopSettingsDocument.Type; type Mutable = { -readonly [K in keyof T]: T[K] }; -const DesktopSettingsJson = fromLenientJson(DesktopSettingsDocument); +interface DropUnreadableKey extends Struct.Lambda { + (field: S): Schema.middlewareDecoding; + readonly "~lambda.out": this["~lambda.in"] extends Schema.Top + ? Schema.middlewareDecoding + : never; +} +// A value this build cannot read drops only its own key, so the rest of the file +// still loads instead of every setting resetting to defaults. +const dropUnreadableKey = Struct.lambda((field) => + field.pipe(Schema.catchDecoding(() => Effect.succeedNone)), +); + +const DesktopSettingsJson = fromLenientJson( + DesktopSettingsDocument.mapFields(Struct.map(dropUnreadableKey)), +); const decodeDesktopSettingsJson = Schema.decodeEffect(DesktopSettingsJson); const encodeDesktopSettingsJson = Schema.encodeEffect(DesktopSettingsJson); const decodeDesktopWindowBounds = Schema.decodeUnknownOption(DesktopWindowBoundsSchema);