Skip to content

Commit c7a3f02

Browse files
fix(desktop): Local environment off survives an unreadable value in desktop-settings.json (#36168)
1 parent 2d8a843 commit c7a3f02

2 files changed

Lines changed: 40 additions & 13 deletions

File tree

‎apps/desktop/src/settings/DesktopAppSettings.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,28 @@ describe("DesktopSettings", () => {
240240
),
241241
);
242242

243+
it.effect("keeps Local environment off when another value in the file is unreadable", () =>
244+
withSettings(
245+
Effect.gen(function* () {
246+
const environment = yield* DesktopEnvironment.DesktopEnvironment;
247+
const fileSystem = yield* FileSystem.FileSystem;
248+
const settings = yield* DesktopAppSettings.DesktopAppSettings;
249+
yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
250+
yield* fileSystem.writeFileString(
251+
environment.desktopSettingsPath,
252+
`{ "localEnvironmentEnabled": false, "serverExposureMode": "tailnet" }\n`,
253+
);
254+
255+
assert.isFalse((yield* settings.load).localEnvironmentEnabled);
256+
yield* settings.setMainWindowBounds({ x: 10, y: 20, width: 800, height: 600 }, false);
257+
assert.include(
258+
yield* fileSystem.readFileString(environment.desktopSettingsPath),
259+
`"localEnvironmentEnabled":false`,
260+
);
261+
}),
262+
),
263+
);
264+
243265
it.effect("rejects window bounds that do not satisfy the domain schema", () =>
244266
withSettings(
245267
Effect.gen(function* () {

‎apps/desktop/src/settings/DesktopAppSettings.ts‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,25 @@ const DesktopWindowBoundsDocument = Schema.Struct({
9090
height: Schema.Number,
9191
});
9292

93+
// A value this build cannot read drops only its own key, so the rest of the file
94+
// still loads and is written back instead of every setting resetting to defaults.
95+
const optionalReadableKey = <S extends Schema.Top>(schema: S) =>
96+
Schema.optionalKey(schema.pipe(Schema.catchDecoding(() => Effect.succeedNone)));
97+
9398
const DesktopSettingsDocument = Schema.Struct({
94-
localEnvironmentEnabled: Schema.optionalKey(Schema.Boolean),
95-
linuxPasswordStore: Schema.optionalKey(Schema.Unknown),
96-
mainWindowBounds: Schema.optionalKey(Schema.NullOr(DesktopWindowBoundsDocument)),
97-
mainWindowMaximized: Schema.optionalKey(Schema.Boolean),
98-
serverExposureMode: Schema.optionalKey(DesktopServerExposureModeSchema),
99-
tailscaleServeEnabled: Schema.optionalKey(Schema.Boolean),
100-
tailscaleServePort: Schema.optionalKey(Schema.Number),
101-
updateChannel: Schema.optionalKey(DesktopUpdateChannelSchema),
102-
updateChannelConfiguredByUser: Schema.optionalKey(Schema.Boolean),
103-
wslBackendEnabled: Schema.optionalKey(Schema.Boolean),
104-
wslMode: Schema.optionalKey(Schema.Literals(["local", "wsl"])),
105-
wslDistro: Schema.optionalKey(Schema.NullOr(Schema.String)),
106-
wslOnly: Schema.optionalKey(Schema.Boolean),
99+
localEnvironmentEnabled: optionalReadableKey(Schema.Boolean),
100+
linuxPasswordStore: optionalReadableKey(Schema.Unknown),
101+
mainWindowBounds: optionalReadableKey(Schema.NullOr(DesktopWindowBoundsDocument)),
102+
mainWindowMaximized: optionalReadableKey(Schema.Boolean),
103+
serverExposureMode: optionalReadableKey(DesktopServerExposureModeSchema),
104+
tailscaleServeEnabled: optionalReadableKey(Schema.Boolean),
105+
tailscaleServePort: optionalReadableKey(Schema.Number),
106+
updateChannel: optionalReadableKey(DesktopUpdateChannelSchema),
107+
updateChannelConfiguredByUser: optionalReadableKey(Schema.Boolean),
108+
wslBackendEnabled: optionalReadableKey(Schema.Boolean),
109+
wslMode: optionalReadableKey(Schema.Literals(["local", "wsl"])),
110+
wslDistro: optionalReadableKey(Schema.NullOr(Schema.String)),
111+
wslOnly: optionalReadableKey(Schema.Boolean),
107112
});
108113

109114
type DesktopSettingsDocument = typeof DesktopSettingsDocument.Type;

0 commit comments

Comments
 (0)