gluon: automatically find best chromium (wip)
This commit is contained in:
parent
932ac3bfa4
commit
d500625958
@ -12,7 +12,7 @@ const presets = { // Presets from OpenAsar
|
|||||||
|
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
|
import { exists } from 'fs/promises';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
@ -20,19 +20,28 @@ const __dirname = dirname(__filename);
|
|||||||
|
|
||||||
import CDP from 'chrome-remote-interface';
|
import CDP from 'chrome-remote-interface';
|
||||||
|
|
||||||
|
const chromiumPathsWin = {
|
||||||
|
stable: join(process.env.PROGRAMFILES, 'Google', 'Chrome', 'Application', 'chrome.exe'),
|
||||||
|
canary: join(process.env.LOCALAPPDATA, 'Google', 'Chrome SxS', 'Application', 'chrome.exe'),
|
||||||
|
edge: join(process.env['PROGRAMFILES(x86)'], 'Microsoft', 'Edge', 'Application', 'msedge.exe')
|
||||||
|
};
|
||||||
|
|
||||||
const findChromiumPath = () => {
|
const findChromiumPath = async () => {
|
||||||
let whichChromium = 'stable';
|
let whichChromium = '';
|
||||||
|
|
||||||
for (const x of [ 'canary', 'edge' ]) {
|
for (const x of [ 'stable', 'canary', 'edge' ]) {
|
||||||
if (process.argv.includes('--' + x)) whichChromium = x;
|
if (process.argv.includes('--' + x)) whichChromium = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (whichChromium) {
|
if (!whichChromium) {
|
||||||
case 'stable': return join(process.env.PROGRAMFILES, 'Google', 'Chrome', 'Application', 'chrome.exe');
|
for (const x in chromiumPathsWin) {
|
||||||
case 'canary': return join(process.env.LOCALAPPDATA, 'Google', 'Chrome SxS', 'Application', 'chrome.exe');
|
if (await exists(chromiumPathsWin[x])) whichChromium = x;
|
||||||
case 'edge': return join(process.env['PROGRAMFILES(x86)'], 'Microsoft', 'Edge', 'Application', 'msedge.exe');
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!whichChromium) return null;
|
||||||
|
|
||||||
|
return chromiumPathsWin[whichChromium];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDataPath = () => join(__dirname, '..', 'chrome_data');
|
const getDataPath = () => join(__dirname, '..', 'chrome_data');
|
||||||
@ -45,6 +54,8 @@ const startChromium = url => new Promise(res => {
|
|||||||
log('chromium path:', chromiumPath);
|
log('chromium path:', chromiumPath);
|
||||||
log('data path:', dataPath);
|
log('data path:', dataPath);
|
||||||
|
|
||||||
|
if (!chromiumPath) return log('failed to find a good chromium install');
|
||||||
|
|
||||||
const debugPort = 9222;
|
const debugPort = 9222;
|
||||||
|
|
||||||
exec(`"${chromiumPath}" --app=${url} --remote-debugging-port=${debugPort} --user-data-dir="${dataPath}" --new-window --disable-extensions --disable-default-apps --disable-breakpad --disable-crashpad --disable-background-networking --disable-domain-reliability --disable-component-update --disable-sync --disable-features=AutofillServerCommunication ${presets.perf}`, (err, stdout, stderr) => {
|
exec(`"${chromiumPath}" --app=${url} --remote-debugging-port=${debugPort} --user-data-dir="${dataPath}" --new-window --disable-extensions --disable-default-apps --disable-breakpad --disable-crashpad --disable-background-networking --disable-domain-reliability --disable-component-update --disable-sync --disable-features=AutofillServerCommunication ${presets.perf}`, (err, stdout, stderr) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user