@mac-bug-screenshot/native-host 1.0.5 → 1.0.8
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 +20 -21
- package/package.json +1 -1
package/README.md
CHANGED
package/host.js
CHANGED
|
@@ -34,7 +34,7 @@ async function capture(outputDir) {
|
|
|
34
34
|
const outputPath = path.join(resolvedDir, `screenshot-${timestamp}.png`);
|
|
35
35
|
|
|
36
36
|
await fs.promises.mkdir(resolvedDir, { recursive: true });
|
|
37
|
-
await runCommand("screencapture", ["-
|
|
37
|
+
await runCommand("screencapture", ["-i", "-s", "-t", "png", outputPath]);
|
|
38
38
|
await runCommand("open", ["-a", "Preview", outputPath]);
|
|
39
39
|
|
|
40
40
|
return outputPath;
|
|
@@ -50,32 +50,29 @@ function writeMessage(message) {
|
|
|
50
50
|
|
|
51
51
|
function readMessage() {
|
|
52
52
|
return new Promise((resolve, reject) => {
|
|
53
|
-
|
|
54
|
-
let lengthOffset = 0;
|
|
53
|
+
let buffer = Buffer.alloc(0);
|
|
55
54
|
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const messageBuffer = Buffer.alloc(length);
|
|
62
|
-
let messageOffset = 0;
|
|
55
|
+
function onData(chunk) {
|
|
56
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
57
|
+
if (buffer.length < 4) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
process.stdin.removeListener("data", readMessageBody);
|
|
69
|
-
resolve(JSON.parse(messageBuffer.toString("utf8")));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
61
|
+
const length = buffer.readUInt32LE(0);
|
|
62
|
+
if (buffer.length < 4 + length) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
72
65
|
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
const messageBuffer = buffer.subarray(4, 4 + length);
|
|
67
|
+
process.stdin.removeListener("data", onData);
|
|
68
|
+
try {
|
|
69
|
+
resolve(JSON.parse(messageBuffer.toString("utf8")));
|
|
70
|
+
} catch (error) {
|
|
71
|
+
reject(error);
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
process.stdin.on("data",
|
|
75
|
+
process.stdin.on("data", onData);
|
|
79
76
|
process.stdin.on("error", reject);
|
|
80
77
|
});
|
|
81
78
|
}
|
|
@@ -92,6 +89,8 @@ async function main() {
|
|
|
92
89
|
writeMessage({ ok: true, outputPath });
|
|
93
90
|
} catch (error) {
|
|
94
91
|
writeMessage({ ok: false, error: error.message });
|
|
92
|
+
} finally {
|
|
93
|
+
setImmediate(() => process.exit(0));
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
|