mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-08 00:47:15 +08:00
make edge on windows can be used as puppeteer executable
This commit is contained in:
+5
-5
@@ -6,7 +6,7 @@ import { is } from '@electron-toolkit/utils'
|
|||||||
import electron from 'electron'
|
import electron from 'electron'
|
||||||
import { saveLastUsedAndAvailableBrowserPath } from './history-utils'
|
import { saveLastUsedAndAvailableBrowserPath } from './history-utils'
|
||||||
|
|
||||||
const expectBuildId = process.env.EXPECT_CHROME_FOR_PUPPETEER_BUILD_ID || '113.0.5672.63'
|
export const EXPECT_CHROMIUM_BUILD_ID = '113.0.5672.63'
|
||||||
const cacheDir = path.join(
|
const cacheDir = path.join(
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
'.geekgeekrun',
|
'.geekgeekrun',
|
||||||
@@ -39,7 +39,7 @@ export const getExpectCachedPuppeteerExecutablePath = async () => {
|
|||||||
return puppeteerManager.computeExecutablePath({
|
return puppeteerManager.computeExecutablePath({
|
||||||
browser: puppeteerManager.Browser.CHROME,
|
browser: puppeteerManager.Browser.CHROME,
|
||||||
cacheDir,
|
cacheDir,
|
||||||
buildId: expectBuildId
|
buildId: EXPECT_CHROMIUM_BUILD_ID
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,13 +70,13 @@ const checkAndDownloadPuppeteerExecutable = async (
|
|||||||
// maybe the exist installation is broken.
|
// maybe the exist installation is broken.
|
||||||
await puppeteerManager.uninstall({
|
await puppeteerManager.uninstall({
|
||||||
cacheDir,
|
cacheDir,
|
||||||
buildId: expectBuildId,
|
buildId: EXPECT_CHROMIUM_BUILD_ID,
|
||||||
browser: puppeteerManager.Browser.CHROME
|
browser: puppeteerManager.Browser.CHROME
|
||||||
})
|
})
|
||||||
installedBrowser = await puppeteerManager.install({
|
installedBrowser = await puppeteerManager.install({
|
||||||
browser: puppeteerManager.Browser.CHROME,
|
browser: puppeteerManager.Browser.CHROME,
|
||||||
cacheDir,
|
cacheDir,
|
||||||
buildId: expectBuildId,
|
buildId: EXPECT_CHROMIUM_BUILD_ID,
|
||||||
downloadProgressCallback: options.downloadProgressCallback
|
downloadProgressCallback: options.downloadProgressCallback
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -84,7 +84,7 @@ const checkAndDownloadPuppeteerExecutable = async (
|
|||||||
await puppeteerManager.getInstalledBrowsers({
|
await puppeteerManager.getInstalledBrowsers({
|
||||||
cacheDir
|
cacheDir
|
||||||
})
|
})
|
||||||
).find((it) => it.buildId === expectBuildId)!
|
).find((it) => it.buildId === EXPECT_CHROMIUM_BUILD_ID)!
|
||||||
}
|
}
|
||||||
await saveLastUsedAndAvailableBrowserPath(await getExpectCachedPuppeteerExecutablePath())
|
await saveLastUsedAndAvailableBrowserPath(await getExpectCachedPuppeteerExecutablePath())
|
||||||
|
|
||||||
|
|||||||
+38
-7
@@ -1,9 +1,42 @@
|
|||||||
import { is } from '@electron-toolkit/utils'
|
import { is } from '@electron-toolkit/utils'
|
||||||
import electron from 'electron'
|
import electron from 'electron'
|
||||||
import * as os from 'node:os'
|
import * as os from 'node:os'
|
||||||
|
import * as fs from 'node:fs'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
import { EXPECT_CHROMIUM_BUILD_ID } from './check-and-download-puppeteer-executable'
|
||||||
|
import {
|
||||||
|
getExecutableFileVersion
|
||||||
|
} from '@geekgeekrun/utils/windows-only/file.mjs'
|
||||||
|
|
||||||
export default async function findAndLocateExistedChromiumExecutable() {
|
export default async function findAndLocateExistedChromiumExecutable() {
|
||||||
|
const exceptChromiumMainVersion = Number(EXPECT_CHROMIUM_BUILD_ID.split('.')[0]) + 1
|
||||||
|
// For windows, try to find Edge(chromium)
|
||||||
|
if (os.platform() === 'win32') {
|
||||||
|
// TODO: handle windows
|
||||||
|
const edgeExecutableLocation = path.join(
|
||||||
|
process.env['ProgramFiles(x86)'],
|
||||||
|
'Microsoft/Edge/Application',
|
||||||
|
'msedge.exe'
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
fs.existsSync(edgeExecutableLocation)
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const version = await getExecutableFileVersion(edgeExecutableLocation)
|
||||||
|
const mainVersion = Number(version.split('.')[0])
|
||||||
|
if ( mainVersion >= exceptChromiumMainVersion) {
|
||||||
|
return {
|
||||||
|
path: edgeExecutableLocation,
|
||||||
|
browser: `Edge ${version}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For other, use findChrome
|
||||||
let findChrome: typeof import('find-chrome-bin').findChrome
|
let findChrome: typeof import('find-chrome-bin').findChrome
|
||||||
if (is.dev) {
|
if (is.dev) {
|
||||||
findChrome = (await import('find-chrome-bin')).findChrome
|
findChrome = (await import('find-chrome-bin')).findChrome
|
||||||
@@ -19,16 +52,14 @@ export default async function findAndLocateExistedChromiumExecutable() {
|
|||||||
)
|
)
|
||||||
).findChromeBin.findChrome
|
).findChromeBin.findChrome
|
||||||
}
|
}
|
||||||
// For windows, try to find Edge(chromium)
|
const targetBrowser = await findChrome({
|
||||||
if (os.platform() === 'win32') {
|
min: exceptChromiumMainVersion
|
||||||
// TODO: handle windows
|
})
|
||||||
}
|
|
||||||
// For other, use findChrome
|
|
||||||
const targetBrowser = await findChrome({})
|
|
||||||
if (!targetBrowser?.executablePath) {
|
if (!targetBrowser?.executablePath) {
|
||||||
throw new Error('NO_EXPECT_CHROMIUM_FOUND')
|
throw new Error('NO_EXPECT_CHROMIUM_FOUND')
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
path: targetBrowser.executablePath
|
path: targetBrowser.executablePath,
|
||||||
|
browser: targetBrowser.browser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import * as childProcess from 'node:child_process'
|
||||||
|
|
||||||
|
export const getExecutableFileVersion = async (p) => {
|
||||||
|
const path = await import('node:path/win32')
|
||||||
|
p = path.resolve(p).replaceAll('\\', '\\\\')
|
||||||
|
return new Promise(
|
||||||
|
(resolve, reject) => {
|
||||||
|
childProcess.exec(
|
||||||
|
`wmic datafile where Name="${
|
||||||
|
p
|
||||||
|
}" get Version /format:list`,
|
||||||
|
(err, stdout) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err)
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
const lines = stdout.trim().split('\n').map(it => it.split('='))
|
||||||
|
const versionLine = lines.find(ln => ln[0] === 'Version')
|
||||||
|
resolve(versionLine?.[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user