diff --git a/.electron-builder.config.js b/.electron-builder.config.js index 9e3cb26..d43a5a9 100644 --- a/.electron-builder.config.js +++ b/.electron-builder.config.js @@ -24,8 +24,8 @@ module.exports = async function () { filter: ['*.node'], }, { - from: 'Chrome-bin', - to: 'Chrome-bin', + from: 'Chrome-bin.zip', + to: 'Chrome-bin.zip', }, { from: 'migrations', diff --git a/.gitattributes b/.gitattributes index 0046d60..bd5c13b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,7 +2,4 @@ scripts/*.js linguist-detectable=false *.config.js linguist-detectable=false * text=auto eol=lf -*.dll filter=lfs diff=lfs merge=lfs -text -Chrome-bin/*.exe filter=lfs diff=lfs merge=lfs -text -Chrome-bin/*.dll filter=lfs diff=lfs merge=lfs -text -Chrome-bin/*.dat filter=lfs diff=lfs merge=lfs -text +Chrome-bin.zip filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index 28b577f..81eff08 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,5 @@ thumbs.db # Editor-based Rest Client .idea/httpRequests -/.idea/csv-plugin.xml \ No newline at end of file +/.idea/csv-plugin.xml +Chrome-bin \ No newline at end of file diff --git a/Chrome-bin.zip b/Chrome-bin.zip new file mode 100644 index 0000000..4003da1 --- /dev/null +++ b/Chrome-bin.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:032663ce91f96c43b207598b4619d568be2579b3d71474bf45cf6c323123b84a +size 165243337 diff --git a/buildResources/icon.png b/buildResources/icon.png index 14c0230..6b4fd8c 100644 Binary files a/buildResources/icon.png and b/buildResources/icon.png differ diff --git a/package-lock.json b/package-lock.json index d2aef7e..2e9b9cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "axios": "^1.5.1", "btoa": "^1.2.1", "electron-updater": "6.1.4", + "extract-zip": "^2.0.1", "http-proxy-agent": "^7.0.0", "https-proxy-agent": "^7.0.2", "i18next": "^23.7.8", diff --git a/package.json b/package.json index fa3c961..8b3b5d9 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "axios": "^1.5.1", "btoa": "^1.2.1", "electron-updater": "6.1.4", + "extract-zip": "^2.0.1", "http-proxy-agent": "^7.0.0", "https-proxy-agent": "^7.0.2", "i18next": "^23.7.8", diff --git a/packages/main/src/fingerprint/index.ts b/packages/main/src/fingerprint/index.ts index bc481e8..77fa039 100644 --- a/packages/main/src/fingerprint/index.ts +++ b/packages/main/src/fingerprint/index.ts @@ -116,9 +116,6 @@ export async function openFingerprintWindow(id: number) { } else { chromePath = join(process.resourcesPath, 'Chrome-bin', 'chrome.exe'); } - logger.info(`env: ${import.meta.env.DEV}`); - logger.info(`Chrome path: ${chromePath}`); - let ipInfo = {timeZone: '', ip: '', ll: [], country: ''}; if (windowData.proxy_id && proxyData.ip) { diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index d82ca24..fed8680 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -6,6 +6,7 @@ import {db, initializeDatabase} from './db'; import {initServices} from './services'; import {createLogger} from '../../shared/utils/logger'; import {MAIN_LOGGER_LABEL} from './constants'; +import {extractChromeBin} from './utils/extract'; const logger = createLogger(MAIN_LOGGER_LABEL); @@ -58,6 +59,16 @@ app } await initServices(); await restoreOrCreateWindow(); + if (!import.meta.env.DEV) { + const {result, error, exist} = await extractChromeBin(); + if (result) { + if (!exist) { + logger.info('Extracted Chrome-bin.zip'); + } + } else { + logger.error('Failed extract Chrome-bin.zip, try to manually extract it', error); + } + } }) .catch(e => logger.error('Failed create window:', e)); diff --git a/packages/main/src/utils/extract.ts b/packages/main/src/utils/extract.ts new file mode 100644 index 0000000..477d030 --- /dev/null +++ b/packages/main/src/utils/extract.ts @@ -0,0 +1,40 @@ +const extract = require('extract-zip'); +import {join} from 'path'; +import {existsSync, mkdirSync, renameSync, rmdirSync} from 'fs'; + +export async function extractChromeBin() { + const resourcesPath = process.resourcesPath; + const chromeZipPath = join(resourcesPath, 'Chrome-bin.zip'); + const tempExtractPath = join(resourcesPath, 'temp-chrome-bin'); + + // 检查临时解压目录是否存在 + if (!existsSync(tempExtractPath)) { + mkdirSync(tempExtractPath); + } + + const chromeBinPath = join(resourcesPath, 'Chrome-bin'); + + // 检查 Chrome-bin 目录是否存在 + if (!existsSync(chromeBinPath)) { + try { + await extract(chromeZipPath, {dir: tempExtractPath}); + console.log('Chrome-bin extraction complete'); + + // 检查并调整目录结构 + const extractedDirPath = join(tempExtractPath, 'Chrome-bin'); + if (existsSync(extractedDirPath)) { + renameSync(extractedDirPath, chromeBinPath); + rmdirSync(tempExtractPath, {recursive: true}); + return {result: true, exist: false}; + } else { + return {result: false, error: 'Expected Chrome-bin directory not found inside ZIP'}; + } + } catch (err) { + console.error('Error extracting Chrome-bin.zip:', err); + return {result: false, error: err}; + } + } else { + console.log('Chrome-bin already exists'); + return {result: true, exist: true}; + } +} diff --git a/types/env.d.ts b/types/env.d.ts index e835ecf..15af430 100644 --- a/types/env.d.ts +++ b/types/env.d.ts @@ -27,4 +27,4 @@ interface ImportMeta { readonly env: ImportMetaEnv; } -// declare module 'portscanner'; +declare module 'portscanner';