@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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/host.js +20 -21
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,7 +22,7 @@ mac-bug-screenshot-install <확장_프로그램_ID>
22
22
  ## 게시 정보
23
23
 
24
24
  - npm 패키지: https://www.npmjs.com/package/@mac-bug-screenshot/native-host
25
- - 현재 버전: 1.0.4
25
+ - 현재 버전: 1.0.5
26
26
 
27
27
  ## 문제 해결
28
28
 
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", ["-x", "-t", "png", outputPath]);
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
- const lengthBuffer = Buffer.alloc(4);
54
- let lengthOffset = 0;
53
+ let buffer = Buffer.alloc(0);
55
54
 
56
- function readLength(chunk) {
57
- chunk.copy(lengthBuffer, lengthOffset);
58
- lengthOffset += chunk.length;
59
- if (lengthOffset >= 4) {
60
- const length = lengthBuffer.readUInt32LE(0);
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
- function readMessageBody(bodyChunk) {
65
- bodyChunk.copy(messageBuffer, messageOffset);
66
- messageOffset += bodyChunk.length;
67
- if (messageOffset >= length) {
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
- process.stdin.removeListener("data", readLength);
74
- process.stdin.on("data", readMessageBody);
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", readLength);
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mac-bug-screenshot/native-host",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "Native messaging host for Mac Bug Screenshot.",
5
5
  "bin": {
6
6
  "mac-bug-screenshot-install": "bin/install.js"