Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

DesktopState.ts

36 lines1.5 KB

1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Ref from "effect/Ref";
5import * as SubscriptionRef from "effect/SubscriptionRef";
6import type { DatabaseMigrationProgress } from "@t3tools/contracts";
7​
8import type { BackendStartupFailure } from "../backend/DesktopBackendManager.ts";
9​
10/** Startup health of the primary local backend, read by the startup recovery window. */
11export type PrimaryBackendStartup =
12 | { readonly _tag: "Starting" }
13 | { readonly _tag: "Ready" }
14 | ({ readonly _tag: "Failing" } & BackendStartupFailure);
15​
16export class DesktopState extends Context.Service<
17 DesktopState,
18 {
19 readonly backendReady: Ref.Ref<boolean>;
20 readonly quitting: Ref.Ref<boolean>;
21 // Set by DesktopUpdates.configure, which runs before the first backend start.
22 readonly canInstallUpdates: Ref.Ref<boolean>;
23 readonly primaryBackendStartup: SubscriptionRef.SubscriptionRef<PrimaryBackendStartup>;
24 readonly databaseMigrationProgress: Ref.Ref<DatabaseMigrationProgress | null>;
25 }
26>()("@t3tools/desktop/app/DesktopState") {}
27​
28const make = Effect.all({
29 backendReady: Ref.make(false),
30 quitting: Ref.make(false),
31 canInstallUpdates: Ref.make(false),
32 primaryBackendStartup: SubscriptionRef.make<PrimaryBackendStartup>({ _tag: "Starting" }),
33 databaseMigrationProgress: Ref.make<DatabaseMigrationProgress | null>(null),
34});
35​
36export const layer = Layer.effect(DesktopState, make);