From 996a57bd2678fa7d8bcebbf9dd5db89ee0223e00 Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Sun, 9 Apr 2023 00:33:43 +0100 Subject: [PATCH] lib/browserPaths: split off into separate file --- src/index.js | 100 +-------------------------------------- src/lib/browserPaths.js | 102 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 99 deletions(-) create mode 100644 src/lib/browserPaths.js diff --git a/src/index.js b/src/index.js index 581d22a..e5af6f0 100644 --- a/src/index.js +++ b/src/index.js @@ -8,111 +8,13 @@ import Firefox from './browser/firefox.js'; import * as ExtensionsAPI from './extensions.js'; import LocalHTTP from './lib/local/http.js'; +import browserPaths from './lib/browserPaths.js'; process.versions.gluon = '0.14.0-alpha.0'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const browserPaths = ({ - 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'), - join(process.env.USERPROFILE, 'scoop', 'apps', 'googlechrome', 'current', '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'), - - chromium: [ - join('Chromium', 'Application', 'chrome.exe'), - join(process.env.USERPROFILE, 'scoop', 'apps', 'chromium', 'current', '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'), - - thorium: join('Thorium', 'Application', 'thorium.exe'), - brave: join('BraveSoftware', 'Brave-Browser', 'Application', 'brave.exe'), - vivaldi: join('Vivaldi', 'Application', 'vivaldi.exe'), - - firefox: [ - join('Mozilla Firefox', 'firefox.exe'), - join(process.env.USERPROFILE, 'scoop', 'apps', 'firefox', 'current', 'firefox.exe') - ], - firefox_developer: join('Firefox Developer Edition', 'firefox.exe'), - firefox_nightly: join('Firefox Nightly', 'firefox.exe'), - - librewolf: join('LibreWolf', 'librewolf.exe'), - waterfox: join('Waterfox', 'waterfox.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_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' ], - - 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' ], - brave: [ 'brave', 'brave-browser' ], - vivaldi: [ 'vivaldi', 'vivaldi-browser' ], - - firefox: [ 'firefox', 'firefox-browser' ], - firefox_nightly: [ 'firefox-nightly', 'firefox-nightly-browser', 'firefox-browser-nightly' ], - - librewolf: [ 'librewolf', 'librewolf-browser' ], - waterfox: [ 'waterfox', 'waterfox-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', - - 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', - - thorium: '/Applications/Thorium.app/Contents/MacOS/Thorium', - brave: '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser', - vivaldi: '/Applications/Vivaldi.app/Contents/MacOS/Vivaldi', - - firefox: '/Applications/Firefox.app/Contents/MacOS/firefox', - firefox_nightly: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox', - - librewolf: '/Applications/LibreWolf.app/Contents/MacOS/librewolf', - waterfox: '/Applications/Waterfox.app/Contents/MacOS/waterfox', - } -})[process.platform]; - -if (process.platform === 'win32') { // windows: automatically generate env-based paths if not arrays - for (const browser in browserPaths) { - const isArray = Array.isArray(browserPaths[browser]); - const basePath = isArray ? browserPaths[browser][0] : browserPaths[browser]; - - browserPaths[browser] = [ - join(process.env.PROGRAMFILES, basePath), - join(process.env.LOCALAPPDATA, basePath), - join(process.env['PROGRAMFILES(x86)'], basePath), - ...(isArray ? browserPaths[browser].slice(1) : []) - ]; - } -} - let _binariesInPath; // cache as to avoid excessive reads const getBinariesInPath = async () => { if (_binariesInPath) return _binariesInPath; diff --git a/src/lib/browserPaths.js b/src/lib/browserPaths.js new file mode 100644 index 0000000..a250322 --- /dev/null +++ b/src/lib/browserPaths.js @@ -0,0 +1,102 @@ +import { join } from 'path'; + +const browserPaths = ({ + 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'), + join(process.env.USERPROFILE, 'scoop', 'apps', 'googlechrome', 'current', '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'), + + chromium: [ + join('Chromium', 'Application', 'chrome.exe'), + join(process.env.USERPROFILE, 'scoop', 'apps', 'chromium', 'current', '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'), + + thorium: join('Thorium', 'Application', 'thorium.exe'), + brave: join('BraveSoftware', 'Brave-Browser', 'Application', 'brave.exe'), + vivaldi: join('Vivaldi', 'Application', 'vivaldi.exe'), + + firefox: [ + join('Mozilla Firefox', 'firefox.exe'), + join(process.env.USERPROFILE, 'scoop', 'apps', 'firefox', 'current', 'firefox.exe') + ], + firefox_developer: join('Firefox Developer Edition', 'firefox.exe'), + firefox_nightly: join('Firefox Nightly', 'firefox.exe'), + + librewolf: join('LibreWolf', 'librewolf.exe'), + waterfox: join('Waterfox', 'waterfox.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_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' ], + + 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' ], + brave: [ 'brave', 'brave-browser' ], + vivaldi: [ 'vivaldi', 'vivaldi-browser' ], + + firefox: [ 'firefox', 'firefox-browser' ], + firefox_nightly: [ 'firefox-nightly', 'firefox-nightly-browser', 'firefox-browser-nightly' ], + + librewolf: [ 'librewolf', 'librewolf-browser' ], + waterfox: [ 'waterfox', 'waterfox-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', + + 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', + + thorium: '/Applications/Thorium.app/Contents/MacOS/Thorium', + brave: '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser', + vivaldi: '/Applications/Vivaldi.app/Contents/MacOS/Vivaldi', + + firefox: '/Applications/Firefox.app/Contents/MacOS/firefox', + firefox_nightly: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox', + + librewolf: '/Applications/LibreWolf.app/Contents/MacOS/librewolf', + waterfox: '/Applications/Waterfox.app/Contents/MacOS/waterfox', + } +})[process.platform]; + +if (process.platform === 'win32') { // windows: automatically generate env-based paths if not arrays + for (const browser in browserPaths) { + const isArray = Array.isArray(browserPaths[browser]); + const basePath = isArray ? browserPaths[browser][0] : browserPaths[browser]; + + browserPaths[browser] = [ + join(process.env.PROGRAMFILES, basePath), + join(process.env.LOCALAPPDATA, basePath), + join(process.env['PROGRAMFILES(x86)'], basePath), + ...(isArray ? browserPaths[browser].slice(1) : []) + ]; + } +} + +export default browserPaths; \ No newline at end of file