@mac-bug-screenshot/native-host 1.0.11 → 1.0.12
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/README.md +1 -1
- package/host.js +31 -10
- package/package.json +1 -1
package/README.md
CHANGED
package/host.js
CHANGED
|
@@ -68,6 +68,29 @@ function runAppleScript(script) {
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
async function openInPreview(filePath) {
|
|
72
|
+
const script = [
|
|
73
|
+
'tell application "Preview"',
|
|
74
|
+
"activate",
|
|
75
|
+
`open POSIX file "${filePath}"`,
|
|
76
|
+
"end tell"
|
|
77
|
+
].join("\n");
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
await runAppleScript(script);
|
|
81
|
+
return;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
// fallback to open command below
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
await runCommandDetailed("open", ["-a", "Preview", filePath]);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
await sleep(300);
|
|
90
|
+
await runCommandDetailed("open", ["-n", "-a", "Preview", filePath]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
71
94
|
async function setPreviewActualSize() {
|
|
72
95
|
const script = [
|
|
73
96
|
'tell application "Preview"',
|
|
@@ -105,29 +128,27 @@ async function readImageSize(filePath) {
|
|
|
105
128
|
}
|
|
106
129
|
}
|
|
107
130
|
|
|
108
|
-
async function capture(outputDir) {
|
|
131
|
+
async function capture(outputDir, mode = "region") {
|
|
109
132
|
const resolvedDir = expandHome(outputDir || DEFAULT_OUTPUT_DIR);
|
|
110
133
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
111
134
|
const outputPath = path.join(resolvedDir, `screenshot-${timestamp}.png`);
|
|
112
135
|
|
|
113
136
|
await fs.promises.mkdir(resolvedDir, { recursive: true });
|
|
114
137
|
await sleep(300);
|
|
138
|
+
const captureArgs = mode === "full"
|
|
139
|
+
? ["-x", "-t", "png", outputPath]
|
|
140
|
+
: ["-i", "-s", "-t", "png", outputPath];
|
|
115
141
|
try {
|
|
116
|
-
await runCommandDetailed("screencapture",
|
|
142
|
+
await runCommandDetailed("screencapture", captureArgs);
|
|
117
143
|
} catch (error) {
|
|
118
144
|
await sleep(300);
|
|
119
|
-
await runCommandDetailed("screencapture",
|
|
145
|
+
await runCommandDetailed("screencapture", captureArgs);
|
|
120
146
|
}
|
|
121
147
|
if (!fs.existsSync(outputPath)) {
|
|
122
148
|
throw new Error("캡처가 취소되었습니다.");
|
|
123
149
|
}
|
|
124
150
|
const dimensions = await readImageSize(outputPath);
|
|
125
|
-
|
|
126
|
-
await runCommandDetailed("open", ["-a", "Preview", outputPath]);
|
|
127
|
-
} catch (error) {
|
|
128
|
-
await sleep(300);
|
|
129
|
-
await runCommandDetailed("open", ["-a", "Preview", outputPath]);
|
|
130
|
-
}
|
|
151
|
+
await openInPreview(outputPath);
|
|
131
152
|
await sleep(200);
|
|
132
153
|
await setPreviewActualSize();
|
|
133
154
|
|
|
@@ -179,7 +200,7 @@ async function main() {
|
|
|
179
200
|
return;
|
|
180
201
|
}
|
|
181
202
|
|
|
182
|
-
const result = await capture(message.outputDir);
|
|
203
|
+
const result = await capture(message.outputDir, message.mode);
|
|
183
204
|
writeMessage({ ok: true, outputPath: result.outputPath, dimensions: result.dimensions });
|
|
184
205
|
} catch (error) {
|
|
185
206
|
writeMessage({ ok: false, error: error.message });
|