feat(coding-agent): add Android/Termux support
- Make @mariozechner/clipboard an optional dependency - Lazy-load clipboard module with graceful fallback - Add Termux clipboard support via termux-clipboard-set - Skip image clipboard on Termux (not supported) fixes #1164
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
import Clipboard from "@mariozechner/clipboard";
|
||||
import { spawnSync } from "child_process";
|
||||
import { createRequire } from "module";
|
||||
|
||||
import { loadPhoton } from "./photon.js";
|
||||
|
||||
type ClipboardModule = {
|
||||
hasImage: () => boolean;
|
||||
getImageBinary: () => Promise<Array<number>>;
|
||||
};
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
let Clipboard: ClipboardModule | null = null;
|
||||
|
||||
try {
|
||||
Clipboard = require("@mariozechner/clipboard") as ClipboardModule;
|
||||
} catch {
|
||||
Clipboard = null;
|
||||
}
|
||||
|
||||
export type ClipboardImage = {
|
||||
bytes: Uint8Array;
|
||||
mimeType: string;
|
||||
@@ -168,12 +182,16 @@ export async function readClipboardImage(options?: {
|
||||
const env = options?.env ?? process.env;
|
||||
const platform = options?.platform ?? process.platform;
|
||||
|
||||
if (env.TERMUX_VERSION) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let image: ClipboardImage | null = null;
|
||||
|
||||
if (platform === "linux" && isWaylandSession(env)) {
|
||||
image = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();
|
||||
} else {
|
||||
if (!Clipboard.hasImage()) {
|
||||
if (!Clipboard || !Clipboard.hasImage()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,16 @@ export function copyToClipboard(text: string): void {
|
||||
} else if (p === "win32") {
|
||||
execSync("clip", options);
|
||||
} else {
|
||||
// Linux - try wl-copy for Wayland, fall back to xclip/xsel for X11
|
||||
// Linux. Try Termux, Wayland, or X11 clipboard tools.
|
||||
if (process.env.TERMUX_VERSION) {
|
||||
try {
|
||||
execSync("termux-clipboard-set", options);
|
||||
return;
|
||||
} catch {
|
||||
// Fall back to Wayland or X11 tools.
|
||||
}
|
||||
}
|
||||
|
||||
const isWayland = isWaylandSession();
|
||||
if (isWayland) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user