@mac-bug-screenshot/native-host 1.0.8 → 1.0.10

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 +69 -3
  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.5
25
+ - 현재 버전: 1.0.9
26
26
 
27
27
  ## 문제 해결
28
28
 
package/host.js CHANGED
@@ -28,6 +28,67 @@ function runCommand(command, args) {
28
28
  });
29
29
  }
30
30
 
31
+ function runCommandOutput(command, args) {
32
+ return new Promise((resolve, reject) => {
33
+ execFile(command, args, (error, stdout) => {
34
+ if (error) {
35
+ reject(error);
36
+ return;
37
+ }
38
+ resolve(stdout);
39
+ });
40
+ });
41
+ }
42
+
43
+ function runAppleScript(script) {
44
+ return new Promise((resolve, reject) => {
45
+ execFile("osascript", ["-e", script], (error) => {
46
+ if (error) {
47
+ reject(error);
48
+ return;
49
+ }
50
+ resolve();
51
+ });
52
+ });
53
+ }
54
+
55
+ async function setPreviewActualSize() {
56
+ const script = [
57
+ 'tell application "Preview"',
58
+ "activate",
59
+ "delay 0.2",
60
+ "tell application \"System Events\" to tell process \"Preview\"",
61
+ "if exists (menu bar 1) then",
62
+ "click menu item \"Actual Size\" of menu 1 of menu item \"Zoom\" of menu 1 of menu bar 1",
63
+ "end if",
64
+ "end tell",
65
+ "end tell"
66
+ ].join("\n");
67
+
68
+ try {
69
+ await runAppleScript(script);
70
+ } catch (error) {
71
+ // Ignore AppleScript failures (permission or menu layout).
72
+ }
73
+ }
74
+
75
+ async function readImageSize(filePath) {
76
+ try {
77
+ const output = await runCommandOutput("sips", ["-g", "pixelWidth", "-g", "pixelHeight", filePath]);
78
+ const widthMatch = output.match(/pixelWidth:\s+(\d+)/);
79
+ const heightMatch = output.match(/pixelHeight:\s+(\d+)/);
80
+ if (!widthMatch || !heightMatch) {
81
+ return null;
82
+ }
83
+ return {
84
+ width: Number(widthMatch[1]),
85
+ height: Number(heightMatch[1])
86
+ };
87
+ } catch (error) {
88
+ return null;
89
+ }
90
+ }
91
+
31
92
  async function capture(outputDir) {
32
93
  const resolvedDir = expandHome(outputDir || DEFAULT_OUTPUT_DIR);
33
94
  const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
@@ -35,9 +96,14 @@ async function capture(outputDir) {
35
96
 
36
97
  await fs.promises.mkdir(resolvedDir, { recursive: true });
37
98
  await runCommand("screencapture", ["-i", "-s", "-t", "png", outputPath]);
99
+ if (!fs.existsSync(outputPath)) {
100
+ throw new Error("캡처가 취소되었습니다.");
101
+ }
102
+ const dimensions = await readImageSize(outputPath);
38
103
  await runCommand("open", ["-a", "Preview", outputPath]);
104
+ await setPreviewActualSize();
39
105
 
40
- return outputPath;
106
+ return { outputPath, dimensions };
41
107
  }
42
108
 
43
109
  function writeMessage(message) {
@@ -85,8 +151,8 @@ async function main() {
85
151
  return;
86
152
  }
87
153
 
88
- const outputPath = await capture(message.outputDir);
89
- writeMessage({ ok: true, outputPath });
154
+ const result = await capture(message.outputDir);
155
+ writeMessage({ ok: true, outputPath: result.outputPath, dimensions: result.dimensions });
90
156
  } catch (error) {
91
157
  writeMessage({ ok: false, error: error.message });
92
158
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mac-bug-screenshot/native-host",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Native messaging host for Mac Bug Screenshot.",
5
5
  "bin": {
6
6
  "mac-bug-screenshot-install": "bin/install.js"