Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/desktop/src/settings/DesktopAppSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
);

Expand Down
17 changes: 16 additions & 1 deletion apps/desktop/src/settings/DesktopAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -104,7 +105,21 @@ const DesktopSettingsDocument = Schema.Struct({
type DesktopSettingsDocument = typeof DesktopSettingsDocument.Type;
type Mutable<T> = { -readonly [K in keyof T]: T[K] };

const DesktopSettingsJson = fromLenientJson(DesktopSettingsDocument);
interface DropUnreadableKey extends Struct.Lambda {
<S extends Schema.Top>(field: S): Schema.middlewareDecoding<S, S["DecodingServices"]>;
readonly "~lambda.out": this["~lambda.in"] extends Schema.Top
? Schema.middlewareDecoding<this["~lambda.in"], this["~lambda.in"]["DecodingServices"]>
: 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<DropUnreadableKey>((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);
Expand Down
Loading