idea-manager 0.9.3 → 0.9.5
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/package.json +1 -1
- package/src/cli.ts +50 -20
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -22,32 +22,44 @@ try {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
async function openAsApp(url: string) {
|
|
25
|
-
const {
|
|
25
|
+
const { execFile: execFileCb } = await import('child_process');
|
|
26
|
+
const fs = await import('fs');
|
|
26
27
|
const platform = process.platform;
|
|
27
28
|
|
|
28
|
-
//
|
|
29
|
-
|
|
29
|
+
// Direct browser binary paths — avoids macOS `open -a --args` being ignored
|
|
30
|
+
// when browser is already running
|
|
31
|
+
const browsers: { bin: string; args: string[] }[] =
|
|
30
32
|
platform === 'darwin'
|
|
31
33
|
? [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
{ bin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', args: [`--app=${url}`] },
|
|
35
|
+
{ bin: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge', args: [`--app=${url}`] },
|
|
36
|
+
{ bin: '/Applications/Chromium.app/Contents/MacOS/Chromium', args: [`--app=${url}`] },
|
|
35
37
|
]
|
|
36
38
|
: platform === 'win32'
|
|
37
39
|
? [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
{ bin: 'chrome', args: [`--app=${url}`] },
|
|
41
|
+
{ bin: 'msedge', args: [`--app=${url}`] },
|
|
42
|
+
]
|
|
41
43
|
: [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
{ bin: 'google-chrome', args: [`--app=${url}`] },
|
|
45
|
+
{ bin: 'chromium-browser', args: [`--app=${url}`] },
|
|
46
|
+
{ bin: 'microsoft-edge', args: [`--app=${url}`] },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
for (const browser of browsers) {
|
|
50
|
+
// On macOS, check binary exists before trying
|
|
51
|
+
if (platform === 'darwin' && !fs.existsSync(browser.bin)) continue;
|
|
46
52
|
|
|
47
|
-
for (const cmd of commands) {
|
|
48
53
|
try {
|
|
49
54
|
await new Promise<void>((resolve, reject) => {
|
|
50
|
-
|
|
55
|
+
const child = execFileCb(browser.bin, browser.args, {
|
|
56
|
+
shell: platform === 'win32',
|
|
57
|
+
detached: true,
|
|
58
|
+
stdio: 'ignore',
|
|
59
|
+
}, (err) => { if (err) reject(err); });
|
|
60
|
+
child.unref();
|
|
61
|
+
// Browser launched — resolve after brief delay
|
|
62
|
+
setTimeout(resolve, 500);
|
|
51
63
|
});
|
|
52
64
|
return; // success
|
|
53
65
|
} catch {
|
|
@@ -130,11 +142,29 @@ program
|
|
|
130
142
|
process.exit(1);
|
|
131
143
|
});
|
|
132
144
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
// Wait for server to be ready, then open browser
|
|
146
|
+
const waitAndOpen = async () => {
|
|
147
|
+
const url = `http://localhost:${port}`;
|
|
148
|
+
for (let i = 0; i < 30; i++) {
|
|
149
|
+
try {
|
|
150
|
+
await new Promise<void>((resolve, reject) => {
|
|
151
|
+
const http = require('http');
|
|
152
|
+
const req = http.get(url, (res: { statusCode: number }) => {
|
|
153
|
+
if (res.statusCode === 200) resolve();
|
|
154
|
+
else reject();
|
|
155
|
+
});
|
|
156
|
+
req.on('error', reject);
|
|
157
|
+
req.setTimeout(1000, () => { req.destroy(); reject(); });
|
|
158
|
+
});
|
|
159
|
+
// Server is ready
|
|
160
|
+
await openAsApp(url);
|
|
161
|
+
return;
|
|
162
|
+
} catch {
|
|
163
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
waitAndOpen().catch(() => {});
|
|
138
168
|
|
|
139
169
|
process.on('SIGINT', () => { child.kill(); process.exit(0); });
|
|
140
170
|
process.on('SIGTERM', () => { child.kill(); process.exit(0); });
|