[codex] Refactor desktop window and update Effect services (#3202)

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and GitHub committed 2026-06-19 21:17:56 -07:00
1 parent df1540f3ac
commit 93fd972108
4 files changed
+50 -52

No files matched your search

+30 -29
View File
@@ -7,7 +7,6 @@ import type {
} from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import * as Data from "effect/Data";
import * as DateTime from "effect/DateTime";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
@@ -60,23 +59,26 @@ const decodeDownloadProgressInfo = Schema.decodeUnknownEffect(DownloadProgressIn
const currentIsoTimestamp = DateTime.now.pipe(Effect.map(DateTime.formatIso));
export class DesktopUpdateActionInProgressError extends Data.TaggedError(
export class DesktopUpdateActionInProgressError extends Schema.TaggedErrorClass<DesktopUpdateActionInProgressError>()(
"DesktopUpdateActionInProgressError",
)<{
readonly action: "check" | "download" | "install";
}> {
override get message() {
{
action: Schema.Literals(["check", "download", "install"]),
},
) {
override get message(): string {
return `Cannot change update tracks while an update ${this.action} action is in progress.`;
}
}
export class DesktopUpdatePersistenceError extends Data.TaggedError(
export class DesktopUpdatePersistenceError extends Schema.TaggedErrorClass<DesktopUpdatePersistenceError>()(
"DesktopUpdatePersistenceError",
)<{
readonly cause: DesktopAppSettings.DesktopSettingsWriteError;
}> {
override get message() {
return "Failed to persist desktop update settings.";
{
cause: Schema.Defect(),
},
) {
override get message(): string {
const detail = this.cause instanceof Error ? this.cause.message : String(this.cause);
return `Failed to persist desktop update settings: ${detail}`;
}
}
@@ -86,22 +88,21 @@ export type DesktopUpdateSetChannelError =
| DesktopUpdateActionInProgressError
| DesktopUpdatePersistenceError;
export interface DesktopUpdatesShape {
readonly getState: Effect.Effect<DesktopUpdateState>;
readonly emitState: Effect.Effect<void>;
readonly disabledReason: Effect.Effect<Option.Option<string>>;
readonly configure: Effect.Effect<void, DesktopUpdateConfigureError, Scope.Scope>;
readonly setChannel: (
channel: DesktopUpdateChannel,
) => Effect.Effect<DesktopUpdateState, DesktopUpdateSetChannelError>;
readonly check: (reason: string) => Effect.Effect<DesktopUpdateCheckResult>;
readonly download: Effect.Effect<DesktopUpdateActionResult>;
readonly install: Effect.Effect<DesktopUpdateActionResult>;
}
export class DesktopUpdates extends Context.Service<DesktopUpdates, DesktopUpdatesShape>()(
"@t3tools/desktop/updates/DesktopUpdates",
) {}
export class DesktopUpdates extends Context.Service<
DesktopUpdates,
{
readonly getState: Effect.Effect<DesktopUpdateState>;
readonly emitState: Effect.Effect<void>;
readonly disabledReason: Effect.Effect<Option.Option<string>>;
readonly configure: Effect.Effect<void, DesktopUpdateConfigureError, Scope.Scope>;
readonly setChannel: (
channel: DesktopUpdateChannel,
) => Effect.Effect<DesktopUpdateState, DesktopUpdateSetChannelError>;
readonly check: (reason: string) => Effect.Effect<DesktopUpdateCheckResult>;
readonly download: Effect.Effect<DesktopUpdateActionResult>;
readonly install: Effect.Effect<DesktopUpdateActionResult>;
}
>()("@t3tools/desktop/updates/DesktopUpdates") {}
const {
logInfo: logUpdaterInfo,
@@ -185,7 +186,7 @@ function isArm64HostRunningIntelBuild(runtimeInfo: DesktopRuntimeInfo): boolean
return runtimeInfo.hostArch === "arm64" && runtimeInfo.appArch === "x64";
}
const make = Effect.gen(function* () {
export const make = Effect.gen(function* () {
const config = yield* DesktopConfig.DesktopConfig;
const backendManager = yield* DesktopBackendManager.DesktopBackendManager;
const desktopState = yield* DesktopState.DesktopState;
@@ -64,7 +64,7 @@ const desktopUpdatesLayer = Layer.succeed(DesktopUpdates.DesktopUpdates, {
check: () => Effect.die("unexpected check"),
download: Effect.die("unexpected download"),
install: Effect.die("unexpected install"),
} satisfies DesktopUpdates.DesktopUpdatesShape);
} satisfies DesktopUpdates.DesktopUpdates["Service"]);
const makeDesktopWindowLayer = (selectedAction: Deferred.Deferred<string>) =>
Layer.succeed(DesktopWindow.DesktopWindow, {
@@ -76,7 +76,7 @@ const makeDesktopWindowLayer = (selectedAction: Deferred.Deferred<string>) =>
handleBackendReady: Effect.void,
dispatchMenuAction: (action) => Deferred.succeed(selectedAction, action).pipe(Effect.asVoid),
syncAppearance: Effect.void,
} satisfies DesktopWindow.DesktopWindowShape);
} satisfies DesktopWindow.DesktopWindow["Service"]);
const makeElectronMenuLayer = (
applicationMenuTemplate: Deferred.Deferred<readonly Electron.MenuItemConstructorOptions[]>,
@@ -14,13 +14,11 @@ import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
import * as DesktopUpdates from "../updates/DesktopUpdates.ts";
import * as DesktopWindow from "./DesktopWindow.ts";
export interface DesktopApplicationMenuShape {
readonly configure: Effect.Effect<void>;
}
export class DesktopApplicationMenu extends Context.Service<
DesktopApplicationMenu,
DesktopApplicationMenuShape
{
readonly configure: Effect.Effect<void>;
}
>()("@t3tools/desktop/window/DesktopApplicationMenu") {}
type DesktopApplicationMenuRuntimeServices =
@@ -94,7 +92,7 @@ const handleCheckForUpdatesMenuClick: Effect.Effect<
yield* checkForUpdatesFromMenu;
}).pipe(Effect.withSpan("desktop.menu.handleCheckForUpdatesClick"));
const make = Effect.gen(function* () {
export const make = Effect.gen(function* () {
const electronApp = yield* ElectronApp.ElectronApp;
const electronMenu = yield* ElectronMenu.ElectronMenu;
const environment = yield* DesktopEnvironment.DesktopEnvironment;
+14 -15
View File
@@ -42,20 +42,19 @@ export type DesktopWindowError =
| ElectronWindow.ElectronWindowCreateError
| PreviewManager.PreviewManagerError;
export interface DesktopWindowShape {
readonly createMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
readonly ensureMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
readonly revealOrCreateMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
readonly activate: Effect.Effect<void, DesktopWindowError>;
readonly createMainIfBackendReady: Effect.Effect<void, DesktopWindowError>;
readonly handleBackendReady: Effect.Effect<void, DesktopWindowError>;
readonly dispatchMenuAction: (action: string) => Effect.Effect<void, DesktopWindowError>;
readonly syncAppearance: Effect.Effect<void>;
}
export class DesktopWindow extends Context.Service<DesktopWindow, DesktopWindowShape>()(
"@t3tools/desktop/window/DesktopWindow",
) {}
export class DesktopWindow extends Context.Service<
DesktopWindow,
{
readonly createMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
readonly ensureMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
readonly revealOrCreateMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
readonly activate: Effect.Effect<void, DesktopWindowError>;
readonly createMainIfBackendReady: Effect.Effect<void, DesktopWindowError>;
readonly handleBackendReady: Effect.Effect<void, DesktopWindowError>;
readonly dispatchMenuAction: (action: string) => Effect.Effect<void, DesktopWindowError>;
readonly syncAppearance: Effect.Effect<void>;
}
>()("@t3tools/desktop/window/DesktopWindow") {}
const { logInfo: logWindowInfo, logWarning: logWindowWarning } =
DesktopObservability.makeComponentLogger("desktop-window");
@@ -143,7 +142,7 @@ function bindFirstRevealTrigger(
}
}
const make = Effect.gen(function* () {
export const make = Effect.gen(function* () {
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const assets = yield* DesktopAssets.DesktopAssets;
const electronMenu = yield* ElectronMenu.ElectronMenu;