Discover installed Chromium executable
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ChildProcess, spawn } from "child_process";
|
||||
import { accessSync, constants } from "fs";
|
||||
import { mkdtemp, rm } from "fs/promises";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
@@ -15,9 +16,26 @@ export class ChromiumFallback {
|
||||
|
||||
constructor(
|
||||
private readonly onExit: (url: string) => void = () => undefined,
|
||||
private readonly executable = process.env.QUEUECUBE_CHROME_BIN || "chromium",
|
||||
private readonly executable = process.env.QUEUECUBE_CHROME_BIN || ChromiumFallback.findExecutable(),
|
||||
) {}
|
||||
|
||||
private static findExecutable(): string {
|
||||
const directories = (process.env.PATH || "").split(path.delimiter);
|
||||
for (const name of ["chromium", "chromium-browser", "google-chrome"]) {
|
||||
for (const directory of directories) {
|
||||
if (!directory) continue;
|
||||
const candidate = path.join(directory, name);
|
||||
try {
|
||||
accessSync(candidate, constants.X_OK);
|
||||
return candidate;
|
||||
} catch {
|
||||
// Keep checking the remaining supported executable names.
|
||||
}
|
||||
}
|
||||
}
|
||||
return "chromium";
|
||||
}
|
||||
|
||||
public get isRunning(): boolean {
|
||||
return this.active !== null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user