Open OAuth login URLs during setup

This commit is contained in:
Advait Paliwal
2026-03-25 10:04:45 -07:00
parent 151956ea24
commit 584d065902
6 changed files with 108 additions and 5 deletions

51
src/system/open-url.ts Normal file
View File

@@ -0,0 +1,51 @@
import { spawn } from "node:child_process";
import { resolveExecutable } from "./executables.js";
type ResolveExecutableFn = (name: string, fallbackPaths?: string[]) => string | undefined;
type OpenUrlCommand = {
command: string;
args: string[];
};
export function getOpenUrlCommand(
url: string,
platform = process.platform,
resolveCommand: ResolveExecutableFn = resolveExecutable,
): OpenUrlCommand | undefined {
if (platform === "win32") {
return {
command: "cmd",
args: ["/c", "start", "", url],
};
}
if (platform === "darwin") {
const command = resolveCommand("open");
return command ? { command, args: [url] } : undefined;
}
const command = resolveCommand("xdg-open");
return command ? { command, args: [url] } : undefined;
}
export function openUrl(url: string): boolean {
const command = getOpenUrlCommand(url);
if (!command) {
return false;
}
try {
const child = spawn(command.command, command.args, {
detached: true,
stdio: "ignore",
windowsHide: true,
});
child.on("error", () => {});
child.unref();
return true;
} catch {
return false;
}
}