pi-image-tools 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +10 -7
- package/package.json +69 -69
- package/src/clipboard.ts +54 -291
- package/src/config.ts +24 -15
- package/src/image-size.ts +62 -63
- package/src/image-transcode.ts +198 -0
- package/src/index.ts +115 -32
- package/src/inline-user-preview.ts +225 -69
- package/src/keybindings.ts +61 -60
- package/src/providers/command-runner.ts +68 -0
- package/src/providers/mac-osascript-pngf.ts +101 -0
- package/src/providers/mac-osascript-publicpng.ts +77 -0
- package/src/providers/mac-pngpaste.ts +69 -0
- package/src/providers/native-module.ts +84 -0
- package/src/providers/powershell-forms.ts +95 -0
- package/src/providers/registry.ts +88 -0
- package/src/providers/types.ts +24 -0
- package/src/providers/wl-paste.ts +81 -0
- package/src/providers/xclip.ts +87 -0
- package/src/recent-images.ts +1 -0
- package/src/shell-environment.ts +75 -0
package/src/recent-images.ts
CHANGED
|
@@ -462,6 +462,7 @@ export function loadRecentImage(
|
|
|
462
462
|
): ClipboardImage {
|
|
463
463
|
assertImageWithinByteLimit(candidate.sizeBytes, `Recent image ${candidate.name}`, environment);
|
|
464
464
|
const raw = readFileSync(candidate.path);
|
|
465
|
+
assertImageWithinByteLimit(raw.length, `Recent image ${candidate.name}`, environment);
|
|
465
466
|
if (raw.length === 0) {
|
|
466
467
|
throw new Error(`File is empty: ${candidate.path}`);
|
|
467
468
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export interface ShellCommandContext {
|
|
4
|
+
platform: NodeJS.Platform;
|
|
5
|
+
environment: NodeJS.ProcessEnv;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type CommandExists = (command: string, context: ShellCommandContext) => boolean;
|
|
9
|
+
|
|
10
|
+
export interface WrappedCommand {
|
|
11
|
+
command: string;
|
|
12
|
+
args: string[];
|
|
13
|
+
wrapped: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const COMMAND_EXISTS_TIMEOUT_MS = 1000;
|
|
17
|
+
const COMMAND_EXISTS_MAX_BUFFER_BYTES = 1024 * 1024;
|
|
18
|
+
const commandExistsCache = new Map<string, boolean>();
|
|
19
|
+
|
|
20
|
+
export function hasGraphicalSession(platform: NodeJS.Platform, environment: NodeJS.ProcessEnv): boolean {
|
|
21
|
+
return platform !== "linux" || Boolean(environment.DISPLAY || environment.WAYLAND_DISPLAY);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isWaylandSession(environment: NodeJS.ProcessEnv): boolean {
|
|
25
|
+
return Boolean(environment.WAYLAND_DISPLAY) || environment.XDG_SESSION_TYPE === "wayland";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isTmuxSession(environment: NodeJS.ProcessEnv): boolean {
|
|
29
|
+
return Boolean(environment.TMUX);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const defaultCommandExists: CommandExists = (command, context) => {
|
|
33
|
+
const lookupCommand = context.platform === "win32" ? "where" : "which";
|
|
34
|
+
const cacheKey = `${context.platform}:${lookupCommand}:${command}:${context.environment.PATH ?? ""}`;
|
|
35
|
+
const cached = commandExistsCache.get(cacheKey);
|
|
36
|
+
if (cached !== undefined) {
|
|
37
|
+
return cached;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const result = spawnSync(lookupCommand, [command], {
|
|
41
|
+
env: context.environment,
|
|
42
|
+
maxBuffer: COMMAND_EXISTS_MAX_BUFFER_BYTES,
|
|
43
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
44
|
+
timeout: COMMAND_EXISTS_TIMEOUT_MS,
|
|
45
|
+
windowsHide: true,
|
|
46
|
+
});
|
|
47
|
+
const exists = !result.error && result.status === 0;
|
|
48
|
+
commandExistsCache.set(cacheKey, exists);
|
|
49
|
+
return exists;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export function buildNamespaceWrappedCommand(
|
|
53
|
+
command: string,
|
|
54
|
+
args: readonly string[],
|
|
55
|
+
context: ShellCommandContext,
|
|
56
|
+
commandExists: CommandExists = defaultCommandExists,
|
|
57
|
+
): WrappedCommand {
|
|
58
|
+
try {
|
|
59
|
+
if (
|
|
60
|
+
context.platform !== "darwin" ||
|
|
61
|
+
!isTmuxSession(context.environment) ||
|
|
62
|
+
!commandExists("reattach-to-user-namespace", context)
|
|
63
|
+
) {
|
|
64
|
+
return { command, args: [...args], wrapped: false };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
command: "reattach-to-user-namespace",
|
|
69
|
+
args: [command, ...args],
|
|
70
|
+
wrapped: true,
|
|
71
|
+
};
|
|
72
|
+
} catch {
|
|
73
|
+
return { command, args: [...args], wrapped: false };
|
|
74
|
+
}
|
|
75
|
+
}
|