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

DesktopState.ts

30 lines1.1 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";
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 readonly primaryBackendStartup: SubscriptionRef.SubscriptionRef<PrimaryBackendStartup>;
21 }
22>()("@t3tools/desktop/app/DesktopState") {}
23​
24const make = Effect.all({
25 backendReady: Ref.make(false),
26 quitting: Ref.make(false),
27 primaryBackendStartup: SubscriptionRef.make<PrimaryBackendStartup>({ _tag: "Starting" }),
28});
29​
30export const layer = Layer.effect(DesktopState, make);