The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as FileSystem from "effect/FileSystem"; |
| 3 | import * as Option from "effect/Option"; |
| 4 | import * as Schema from "effect/Schema"; |
| 5 | import * as Electron from "electron"; |
| 6 | |
| 7 | import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts"; |
| 8 | import * as ElectronWindow from "../../electron/ElectronWindow.ts"; |
| 9 | import * as IpcChannels from "../channels.ts"; |
| 10 | import { makeIpcMethod } from "../DesktopIpc.ts"; |
| 11 | import { getHostEnvironmentId } from "./localEnvironment.ts"; |
| 12 | |
| 13 | export const startFileDrag = makeIpcMethod({ |
| 14 | channel: IpcChannels.START_FILE_DRAG_CHANNEL, |
| 15 | payload: Schema.Struct({ environmentId: Schema.String, path: Schema.String }), |
| 16 | result: Schema.Boolean, |
| 17 | handler: Effect.fn("desktop.ipc.fileDrag.start")(function* (input, event) { |
| 18 | const environment = yield* DesktopEnvironment.DesktopEnvironment; |
| 19 | if (environment.platform !== "darwin" && environment.platform !== "win32") return false; |
| 20 | if (!environment.path.isAbsolute(input.path)) return false; |
| 21 | const hostEnvironmentId = yield* getHostEnvironmentId.handler(undefined); |
| 22 | if (hostEnvironmentId === null || input.environmentId !== hostEnvironmentId) return false; |
| 23 | const window = yield* (yield* ElectronWindow.ElectronWindow).main; |
| 24 | if (Option.isNone(window) || event?.sender.id !== window.value.webContents.id) return false; |
| 25 | const fs = yield* FileSystem.FileSystem; |
| 26 | if (!(yield* fs.exists(input.path))) return false; |
| 27 | return yield* Effect.promise(async () => { |
| 28 | try { |
| 29 | const icon = await Electron.app.getFileIcon(input.path, { size: "normal" }); |
| 30 | window.value.webContents.startDrag({ file: input.path, icon }); |
| 31 | return true; |
| 32 | } catch { |
| 33 | return false; |
| 34 | } |
| 35 | }); |
| 36 | }), |
| 37 | }); |