@mac-bug-screenshot/native-host 1.0.10 → 1.0.11
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 +30 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/host.js
CHANGED
|
@@ -28,6 +28,18 @@ function runCommand(command, args) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
function runCommandDetailed(command, args) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
execFile(command, args, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
34
|
+
if (error) {
|
|
35
|
+
reject(new Error(stderr || error.message));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
resolve({ stdout, stderr });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
function runCommandOutput(command, args) {
|
|
32
44
|
return new Promise((resolve, reject) => {
|
|
33
45
|
execFile(command, args, (error, stdout) => {
|
|
@@ -40,6 +52,10 @@ function runCommandOutput(command, args) {
|
|
|
40
52
|
});
|
|
41
53
|
}
|
|
42
54
|
|
|
55
|
+
function sleep(ms) {
|
|
56
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
function runAppleScript(script) {
|
|
44
60
|
return new Promise((resolve, reject) => {
|
|
45
61
|
execFile("osascript", ["-e", script], (error) => {
|
|
@@ -95,12 +111,24 @@ async function capture(outputDir) {
|
|
|
95
111
|
const outputPath = path.join(resolvedDir, `screenshot-${timestamp}.png`);
|
|
96
112
|
|
|
97
113
|
await fs.promises.mkdir(resolvedDir, { recursive: true });
|
|
98
|
-
await
|
|
114
|
+
await sleep(300);
|
|
115
|
+
try {
|
|
116
|
+
await runCommandDetailed("screencapture", ["-i", "-s", "-t", "png", outputPath]);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
await sleep(300);
|
|
119
|
+
await runCommandDetailed("screencapture", ["-i", "-s", "-t", "png", outputPath]);
|
|
120
|
+
}
|
|
99
121
|
if (!fs.existsSync(outputPath)) {
|
|
100
122
|
throw new Error("캡처가 취소되었습니다.");
|
|
101
123
|
}
|
|
102
124
|
const dimensions = await readImageSize(outputPath);
|
|
103
|
-
|
|
125
|
+
try {
|
|
126
|
+
await runCommandDetailed("open", ["-a", "Preview", outputPath]);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
await sleep(300);
|
|
129
|
+
await runCommandDetailed("open", ["-a", "Preview", outputPath]);
|
|
130
|
+
}
|
|
131
|
+
await sleep(200);
|
|
104
132
|
await setPreviewActualSize();
|
|
105
133
|
|
|
106
134
|
return { outputPath, dimensions };
|