paths: add new browsers, refactor windows to auto append env
This commit is contained in:
parent
13b662f144
commit
bc0cb706f5
8
gluon.d.ts
vendored
8
gluon.d.ts
vendored
@ -161,7 +161,13 @@ type Window = {
|
||||
|
||||
|
||||
/** A browser that Gluon supports. */
|
||||
type Browser = 'chrome'|'chrome_canary'|'chromium'|'chromium_snapshot'|'edge'|'firefox'|'firefox_nightly';
|
||||
type Browser =
|
||||
'chrome'|'chrome_beta'|'chrome_dev'|'chrome_canary'|
|
||||
'chromium'|'chromium_snapshot'|
|
||||
'edge'|'edge_beta'|'edge_dev'|'edge_canary'|
|
||||
'firefox'|'firefox_nightly'|
|
||||
'thorium'|
|
||||
'librewolf';
|
||||
|
||||
/** A browser engine that Gluon supports. */
|
||||
type BrowserEngine = 'chromium'|'firefox';
|
||||
|
92
src/index.js
92
src/index.js
@ -17,60 +17,82 @@ const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const browserPaths = ({
|
||||
win32: process.platform === 'win32' && {
|
||||
chrome: [
|
||||
join(process.env.PROGRAMFILES, 'Google', 'Chrome', 'Application', 'chrome.exe'),
|
||||
join(process.env.LOCALAPPDATA, 'Google', 'Chrome', 'Application', 'chrome.exe')
|
||||
],
|
||||
chrome_canary: [
|
||||
join(process.env.PROGRAMFILES, 'Google', 'Chrome', 'Application', 'chrome.exe'),
|
||||
join(process.env.LOCALAPPDATA, 'Google', 'Chrome SxS', 'Application', 'chrome.exe')
|
||||
],
|
||||
win32: process.platform === 'win32' && { // windows paths are automatically prepended with program files, program files (x86), and local appdata if a string, see below
|
||||
chrome: join('Google', 'Chrome', 'Application', 'chrome.exe'),
|
||||
chrome_beta: join('Google', 'Chrome Beta', 'Application', 'chrome.exe'),
|
||||
chrome_dev: join('Google', 'Chrome Dev', 'Application', 'chrome.exe'),
|
||||
chrome_canary: join('Google', 'Chrome SxS', 'Application', 'chrome.exe'),
|
||||
|
||||
edge: [
|
||||
join(process.env['PROGRAMFILES(x86)'], 'Microsoft', 'Edge', 'Application', 'msedge.exe'),
|
||||
join(process.env.PROGRAMFILES, 'Microsoft', 'Edge', 'Application', 'msedge.exe'),
|
||||
join(process.env.LOCALAPPDATA, 'Microsoft', 'Edge', 'Application', 'msedge.exe'),
|
||||
],
|
||||
chromium: join('Chromium', 'Application', 'chrome.exe'),
|
||||
|
||||
chromium: [
|
||||
join(process.env.PROGRAMFILES, 'Chromium', 'Application', 'chrome.exe'),
|
||||
join(process.env.LOCALAPPDATA, 'Chromium', 'Application', 'chrome.exe'),
|
||||
],
|
||||
edge: join('Microsoft', 'Edge', 'Application', 'msedge.exe'),
|
||||
edge_beta: join('Microsoft', 'Edge Beta', 'Application', 'msedge.exe'),
|
||||
edge_dev: join('Microsoft', 'Edge Dev', 'Application', 'msedge.exe'),
|
||||
edge_canary: join('Microsoft', 'Edge SxS', 'Application', 'msedge.exe'),
|
||||
|
||||
firefox: [
|
||||
join(process.env.PROGRAMFILES, 'Mozilla Firefox', 'firefox.exe'),
|
||||
join(process.env.LOCALAPPDATA, 'Mozilla Firefox', 'firefox.exe'),
|
||||
],
|
||||
firefox_nightly: [
|
||||
join(process.env.PROGRAMFILES, 'Firefox Nightly', 'firefox.exe'),
|
||||
join(process.env.LOCALAPPDATA, 'Firefox Nightly', 'firefox.exe'),
|
||||
]
|
||||
thorium: join('Thorium', 'Application', 'thorium.exe'),
|
||||
|
||||
firefox: join('Mozilla Firefox', 'firefox.exe'),
|
||||
firefox_developer: join('Firefox Developer Edition', 'firefox.exe'),
|
||||
firefox_nightly: join('Firefox Nightly', 'firefox.exe'),
|
||||
|
||||
librewolf: join('LibreWolf', 'librewolf.exe'),
|
||||
},
|
||||
|
||||
linux: { // these should be in path so just use the name of the binary
|
||||
chrome: [ 'chrome', 'google-chrome', 'chrome-browser', 'google-chrome-stable' ],
|
||||
chrome_canary: [ 'chrome-canary', 'google-chrome-canary', 'google-chrome-unstable', 'chrome-unstable' ],
|
||||
chrome_beta: [ 'chrome-beta', 'google-chrome-beta', 'chrome-beta-browser', 'chrome-browser-beta' ],
|
||||
chrome_dev: [ 'chrome-unstable', 'google-chrome-unstable', 'chrome-unstable-browser', 'chrome-browser-unstable' ],
|
||||
chrome_canary: [ 'chrome-canary', 'google-chrome-canary', 'chrome-canary-browser', 'chrome-browser-canary' ],
|
||||
|
||||
chromium: [ 'chromium', 'chromium-browser' ],
|
||||
chromium_snapshot: [ 'chromium-snapshot', 'chromium-snapshot-bin' ],
|
||||
|
||||
firefox: 'firefox',
|
||||
firefox_nightly: 'firefox-nightly'
|
||||
edge: [ 'microsoft-edge', 'microsoft-edge-stable', 'microsoft-edge-browser' ],
|
||||
edge_beta: [ 'microsoft-edge-beta', 'microsoft-edge-browser-beta', 'microsoft-edge-beta-browser' ],
|
||||
edge_dev: [ 'microsoft-edge-dev', 'microsoft-edge-browser-dev', 'microsoft-edge-dev-browser' ],
|
||||
edge_canary: [ 'microsoft-edge-canary', 'microsoft-edge-browser-canary', 'microsoft-edge-canary-browser' ],
|
||||
|
||||
thorium: [ 'thorium', 'thorium-browser' ],
|
||||
|
||||
firefox: [ 'firefox', 'firefox-browser' ],
|
||||
firefox_nightly: [ 'firefox-nightly', 'firefox-nightly-browser', 'firefox-browser-nightly' ],
|
||||
|
||||
librewolf: [ 'librewolf', 'librewolf-browser' ]
|
||||
},
|
||||
|
||||
darwin: {
|
||||
chrome: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
chrome_beta: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome Beta',
|
||||
chrome_dev: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome Dev',
|
||||
chrome_canary: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
|
||||
edge: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
||||
|
||||
chromium: '/Applications/Chromium.app/Contents/MacOS/Chromium',
|
||||
|
||||
edge: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
||||
edge_beta: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge Beta',
|
||||
edge_dev: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge Dev',
|
||||
edge_canary: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge Canary',
|
||||
|
||||
firefox: '/Applications/Firefox.app/Contents/MacOS/firefox',
|
||||
firefox_nightly: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox'
|
||||
}
|
||||
})[process.platform];
|
||||
|
||||
if (process.platform === 'win32') { // windows: automatically generate env-based paths if not arrays
|
||||
for (const browser in browserPaths) {
|
||||
if (!Array.isArray(browserPaths[browser])) {
|
||||
const basePath = browserPaths[browser];
|
||||
|
||||
browserPaths[browser] = [
|
||||
join(process.env.PROGRAMFILES, basePath),
|
||||
join(process.env.LOCALAPPDATA, basePath),
|
||||
join(process.env['PROGRAMFILES(x86)'], basePath)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _binariesInPath; // cache as to avoid excessive reads
|
||||
const getBinariesInPath = async () => {
|
||||
if (_binariesInPath) return _binariesInPath;
|
||||
@ -118,6 +140,13 @@ const findBrowserPath = async (forceBrowser) => {
|
||||
const getFriendlyName = whichBrowser => whichBrowser[0].toUpperCase() + whichBrowser.slice(1).replace(/[a-z]_[a-z]/g, _ => _[0] + ' ' + _[2].toUpperCase());
|
||||
const getDataPath = () => join(__dirname, '..', 'chrome_data');
|
||||
|
||||
const getBrowserType = name => { // todo: not need this
|
||||
if (name.startsWith('firefox') ||
|
||||
[ 'librewolf' ].includes(name)) return 'firefox';
|
||||
|
||||
return 'chromium';
|
||||
};
|
||||
|
||||
const startBrowser = async (url, { windowSize, forceBrowser }) => {
|
||||
const dataPath = getDataPath();
|
||||
|
||||
@ -130,8 +159,7 @@ const startBrowser = async (url, { windowSize, forceBrowser }) => {
|
||||
|
||||
if (!browserPath) return log('failed to find a good browser install');
|
||||
|
||||
const browserType = browserName.startsWith('firefox') ? 'firefox' : 'chromium';
|
||||
|
||||
const browserType = getBrowserType(browserName);
|
||||
const Window = await (browserType === 'firefox' ? Firefox : Chromium)({
|
||||
browserName: browserFriendlyName,
|
||||
dataPath,
|
||||
|
Loading…
x
Reference in New Issue
Block a user