@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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/host.js +30 -2
  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.9
25
+ - 현재 버전: 1.0.10
26
26
 
27
27
  ## 문제 해결
28
28
 
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 runCommand("screencapture", ["-i", "-s", "-t", "png", outputPath]);
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
- await runCommand("open", ["-a", "Preview", outputPath]);
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mac-bug-screenshot/native-host",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Native messaging host for Mac Bug Screenshot.",
5
5
  "bin": {
6
6
  "mac-bug-screenshot-install": "bin/install.js"