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