| 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: DesktopUpdateChannelSchema, |
| 27 | result: DesktopUpdateStateSchema, |
| 28 | handler: Effect.fn("desktop.ipc.updates.setChannel")(function* (channel) { |
| 29 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 30 | return yield* updates.setChannel(channel); |
| 31 | }), |
| 32 | }); |
| 33 | |
| 34 | export const downloadUpdate = DesktopIpc.makeIpcMethod({ |
| 35 | channel: IpcChannels.UPDATE_DOWNLOAD_CHANNEL, |
| 36 | payload: Schema.Void, |
| 37 | result: DesktopUpdateActionResultSchema, |
| 38 | handler: Effect.fn("desktop.ipc.updates.download")(function* () { |
| 39 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 40 | return yield* updates.download; |
| 41 | }), |
| 42 | }); |
| 43 | |
| 44 | export const installUpdate = DesktopIpc.makeIpcMethod({ |
| 45 | channel: IpcChannels.UPDATE_INSTALL_CHANNEL, |
| 46 | payload: Schema.Void, |
| 47 | result: DesktopUpdateActionResultSchema, |
| 48 | handler: Effect.fn("desktop.ipc.updates.install")(function* () { |
| 49 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 50 | return yield* updates.install; |
| 51 | }), |
| 52 | }); |
| 53 | |
| 54 | export const checkForUpdate = DesktopIpc.makeIpcMethod({ |
| 55 | channel: IpcChannels.UPDATE_CHECK_CHANNEL, |
| 56 | payload: Schema.Void, |
| 57 | result: DesktopUpdateCheckResultSchema, |
| 58 | handler: Effect.fn("desktop.ipc.updates.check")(function* () { |
| 59 | const updates = yield* DesktopUpdates.DesktopUpdates; |
| 60 | return yield* updates.check("web-ui"); |
| 61 | }), |
| 62 | }); |