resumecontext 0.1.2 → 0.1.3
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/dist/browser.js +26 -14
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
2
|
+
/** Starts `command` detached and forgets about it. A missing command (no
|
|
3
|
+
* xdg-open on a headless server, say) is not thrown by spawn: it arrives
|
|
4
|
+
* later as an 'error' event, and an EventEmitter with no 'error' listener
|
|
5
|
+
* crashes the whole process. So both the synchronous throw and the event
|
|
6
|
+
* are swallowed here. */
|
|
7
|
+
export function launchDetached(command, args, options = {}) {
|
|
6
8
|
try {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
spawn("xdg-open", [url], { stdio: "ignore", detached: true }).unref();
|
|
15
|
-
}
|
|
9
|
+
const child = spawn(command, args, { stdio: "ignore", detached: true, ...options });
|
|
10
|
+
child.on("error", () => {
|
|
11
|
+
// fine -- the caller has a fallback
|
|
12
|
+
});
|
|
13
|
+
child.unref();
|
|
16
14
|
}
|
|
17
15
|
catch {
|
|
18
|
-
// fine --
|
|
16
|
+
// fine -- the caller has a fallback
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Best-effort -- opens the user's default browser to `url`. Never throws
|
|
20
|
+
* and never crashes the CLI: the URL is always printed first, so a failure
|
|
21
|
+
* here just means the user opens it by hand instead of automatically. */
|
|
22
|
+
export function openInBrowser(url) {
|
|
23
|
+
if (process.platform === "darwin") {
|
|
24
|
+
launchDetached("open", [url]);
|
|
25
|
+
}
|
|
26
|
+
else if (process.platform === "win32") {
|
|
27
|
+
launchDetached("cmd", ["/c", "start", '""', url], { shell: true });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
launchDetached("xdg-open", [url]);
|
|
19
31
|
}
|
|
20
32
|
}
|