Open History to see the last commit
1import { DEFAULT_CLIENT_SETTINGS, type ClientSettings } from "@t3tools/contracts";
2import * as Effect from "effect/Effect";
3import * as Option from "effect/Option";
4
5import * as ElectronPowerSaveBlocker from "../electron/ElectronPowerSaveBlocker.ts";
6import * as DesktopClientSettings from "../settings/DesktopClientSettings.ts";
7
8export const applyClientSettings = Effect.fn("desktop.sleepPrevention.applyClientSettings")(
9 function* (settings: ClientSettings) {
10 const powerSaveBlocker = yield* ElectronPowerSaveBlocker.ElectronPowerSaveBlocker;
11 yield* powerSaveBlocker.setKeepAwake(settings.preventSleepForRemoteConnections);
12 },
13);
14
15/** Restore the assertion before the backend starts, independently of a window. */
16export const restore = Effect.fn("desktop.sleepPrevention.restore")(function* () {
17 const clientSettings = yield* DesktopClientSettings.DesktopClientSettings;
18 const persistedSettings = yield* clientSettings.get;
19 yield* applyClientSettings(Option.getOrElse(persistedSettings, () => DEFAULT_CLIENT_SETTINGS));
20});