@mac-bug-screenshot/native-host 1.0.4 → 1.0.6
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/bin/install.js +7 -15
- package/host.js +19 -20
- package/package.json +1 -1
package/README.md
CHANGED
package/bin/install.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const os = require("os");
|
|
5
|
-
const { execSync } = require("child_process");
|
|
6
5
|
|
|
7
6
|
const HOST_NAME = "com.sobbangcompany.mac_bug_screenshot";
|
|
8
7
|
const ROOT_DIR = path.resolve(__dirname, "..");
|
|
9
8
|
const TEMPLATE_PATH = path.join(ROOT_DIR, "manifest.template.json");
|
|
10
|
-
const HOST_PATH =
|
|
9
|
+
const HOST_PATH = path.join(ROOT_DIR, "host.js");
|
|
11
10
|
const WRAPPER_DIR = path.join(os.homedir(), ".mac-bug-screenshot");
|
|
12
11
|
const WRAPPER_PATH = path.join(WRAPPER_DIR, "native-host.sh");
|
|
13
12
|
const TARGET_DIR = path.join(
|
|
@@ -36,13 +35,18 @@ function main() {
|
|
|
36
35
|
.replace(/__HOST_PATH__/g, WRAPPER_PATH)
|
|
37
36
|
.replace(/__EXTENSION_ID__/g, extensionId);
|
|
38
37
|
|
|
38
|
+
if (!fs.existsSync(HOST_PATH)) {
|
|
39
|
+
console.error("host.js를 찾을 수 없습니다:", HOST_PATH);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
fs.mkdirSync(WRAPPER_DIR, { recursive: true });
|
|
40
44
|
const wrapperScript = [
|
|
41
45
|
"#!/bin/sh",
|
|
42
46
|
`NODE_PATH="${process.execPath}"`,
|
|
43
47
|
`HOST_PATH="${HOST_PATH}"`,
|
|
44
48
|
'exec "$NODE_PATH" "$HOST_PATH"'
|
|
45
|
-
].join("\n");
|
|
49
|
+
].join("\n") + "\n";
|
|
46
50
|
fs.writeFileSync(WRAPPER_PATH, wrapperScript);
|
|
47
51
|
fs.chmodSync(WRAPPER_PATH, 0o755);
|
|
48
52
|
|
|
@@ -54,16 +58,4 @@ function main() {
|
|
|
54
58
|
console.log(TARGET_PATH);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
function resolveGlobalHostPath() {
|
|
58
|
-
try {
|
|
59
|
-
const npmRoot = execSync("npm root -g", { encoding: "utf8" }).trim();
|
|
60
|
-
if (npmRoot) {
|
|
61
|
-
return path.join(npmRoot, "@mac-bug-screenshot", "native-host", "host.js");
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
// fallback to local package path
|
|
65
|
-
}
|
|
66
|
-
return path.join(ROOT_DIR, "host.js");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
61
|
main();
|
package/host.js
CHANGED
|
@@ -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
|
|