@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 20 lines 742 Bytes
Raw
1 import type { DesktopBridge } from "@t3tools/contracts";
2
3 export const DESKTOP_PASTE_AS_TEXT_EVENT = "t3:paste-as-text";
4
5 /**
6 * Arm composer paste handling before Electron delivers the native clipboard event. The event
7 * bubbles from the focused element, so a composer can listen on its own form or on `target`.
8 */
9 export function installDesktopPasteAsText(
10 bridge: Pick<DesktopBridge, "onMenuAction" | "pasteAsText"> | undefined,
11 target: EventTarget,
12 ): (() => void) | undefined {
13 return bridge?.onMenuAction((action) => {
14 if (action !== "paste-as-text") return;
15 (document.activeElement ?? target).dispatchEvent(
16 new Event(DESKTOP_PASTE_AS_TEXT_EVENT, { bubbles: true }),
17 );
18 void bridge.pasteAsText();
19 });
20 }