The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | DesktopUpdateActionResultSchema, |
| 3 | DesktopUpdateChannelSchema, |
| 4 | DesktopUpdateCheckResultSchema, |
| 5 | DesktopUpdateStateSchema, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Schema from "effect/Schema"; |
| 9 | |
| 10 | import * as DesktopUpdates from "../../updates/DesktopUpdates.ts"; |
| 11 | import * as IpcChannels from "../channels.ts"; |
| 12 | import * as DesktopIpc from "../DesktopIpc.ts"; |
| 13 | |
| 14 | export const getUpdateState = DesktopIpc.makeIpcMethod({ |
| 15 | channel: IpcChannels.UPDATE_GET_STATE_CHANNEL, |
| 16 | payload: Schema.Void, |
| 17 | result: DesktopUpdateStateSchema, |
| 18 | handler: Effect.fn("desktop.ipc.updates.getState")(function* () { |
| 19 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 20 | return yield* updates.getState; |
| 21 | }), |
| 22 | }); |
| 23 | |
| 24 | export const setUpdateChannel = DesktopIpc.makeIpcMethod({ |
| 25 | channel: IpcChannels.UPDATE_SET_CHANNEL_CHANNEL, |
| 26 | payload: Schema.Struct({ |
| 27 | channel: DesktopUpdateChannelSchema, |
| 28 | minimumVersion: Schema.optional(Schema.String), |
| 29 | }), |
| 30 | result: DesktopUpdateStateSchema, |
| 31 | handler: Effect.fn("desktop.ipc.updates.setChannel")(function* ({ channel, minimumVersion }) { |
| 32 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 33 | return yield* updates.setChannel(channel, { minimumVersion }); |
| 34 | }), |
| 35 | }); |
| 36 | |
| 37 | export const downloadUpdate = DesktopIpc.makeIpcMethod({ |
| 38 | channel: IpcChannels.UPDATE_DOWNLOAD_CHANNEL, |
| 39 | payload: Schema.Void, |
| 40 | result: DesktopUpdateActionResultSchema, |
| 41 | handler: Effect.fn("desktop.ipc.updates.download")(function* () { |
| 42 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 43 | return yield* updates.download; |
| 44 | }), |
| 45 | }); |
| 46 | |
| 47 | export const installUpdate = DesktopIpc.makeIpcMethod({ |
| 48 | channel: IpcChannels.UPDATE_INSTALL_CHANNEL, |
| 49 | /** A version installs only that downloaded build, never one that replaced it. */ |
| 50 | payload: Schema.UndefinedOr(Schema.String), |
| 51 | result: DesktopUpdateActionResultSchema, |
| 52 | handler: Effect.fn("desktop.ipc.updates.install")(function* (expectedVersion) { |
| 53 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 54 | if (expectedVersion === undefined) return yield* updates.install; |
| 55 | const { accepted, completed, state } = yield* updates.installPrepared(expectedVersion); |
| 56 | return { accepted, completed, state }; |
| 57 | }), |
| 58 | }); |
| 59 | |
| 60 | export const checkForUpdate = DesktopIpc.makeIpcMethod({ |
| 61 | channel: IpcChannels.UPDATE_CHECK_CHANNEL, |
| 62 | payload: Schema.Void, |
| 63 | result: DesktopUpdateCheckResultSchema, |
| 64 | handler: Effect.fn("desktop.ipc.updates.check")(function* () { |
| 65 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 66 | return yield* updates.check("web-ui"); |
| 67 | }), |
| 68 | }); |