From 74a8e5a2ef55f777483e4e009c2eecd5b883becc Mon Sep 17 00:00:00 2001 From: zmzimpl Date: Fri, 22 Mar 2024 18:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BC=93=E5=AD=98=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=EF=BC=8C=E9=81=BF=E5=85=8D=E5=8D=B8=E8=BD=BD=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=90=8E=E6=B8=85=E7=90=86=20chrome/chromium=20?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .electron-builder.config.js | 4 ++-- packages/main/src/fingerprint/device.ts | 9 +++++++++ packages/main/src/fingerprint/index.ts | 9 +++------ packages/main/src/services/common-service.ts | 1 + packages/main/src/utils/get-settings.ts | 4 ++-- scripts/uninstall.nsis | 0 6 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 scripts/uninstall.nsis diff --git a/.electron-builder.config.js b/.electron-builder.config.js index 852f87c..e74b135 100644 --- a/.electron-builder.config.js +++ b/.electron-builder.config.js @@ -11,7 +11,7 @@ module.exports = async function () { const {getVersion} = await import('./version/getVersion.mjs'); return { - productName: 'chrome-power', + productName: 'chrome-power-alpha', directories: { output: 'dist', buildResources: 'buildResources', @@ -46,7 +46,7 @@ module.exports = async function () { allowToChangeInstallationDirectory: true, createDesktopShortcut: true, createStartMenuShortcut: true, - shortcutName: 'chrome-power', + shortcutName: 'chrome-power-alpha', }, win: { diff --git a/packages/main/src/fingerprint/device.ts b/packages/main/src/fingerprint/device.ts index 7db097c..16f54f6 100644 --- a/packages/main/src/fingerprint/device.ts +++ b/packages/main/src/fingerprint/device.ts @@ -2,6 +2,7 @@ import {execSync} from 'child_process'; import * as os from 'os'; import {createLogger} from '../../../shared/utils/logger'; import {APP_LOGGER_LABEL} from '../constants'; +import {parse} from 'path'; const logger = createLogger(APP_LOGGER_LABEL); @@ -56,3 +57,11 @@ export function getChromePath() { } return chromePath; } + +export function getRootDir() { + const installationPath = process.resourcesPath; + const parsedPath = parse(installationPath); + // 获取根目录 + const rootDirectory = parsedPath.root; + return rootDirectory; +} diff --git a/packages/main/src/fingerprint/index.ts b/packages/main/src/fingerprint/index.ts index 7b9fb3b..63ef3ba 100644 --- a/packages/main/src/fingerprint/index.ts +++ b/packages/main/src/fingerprint/index.ts @@ -113,12 +113,8 @@ export async function openFingerprintWindow(id: number) { const proxyType = proxyData?.proxy_type?.toLowerCase(); const settings = getSettings(); - let cachePath; - if (settings.profileCachePath) { - cachePath = settings.profileCachePath; - } else { - cachePath = join(process.resourcesPath, 'chromePowerCache'); - } + const cachePath = settings.profileCachePath; + const win = BrowserWindow.getAllWindows()[0]; const windowDataDir = join( cachePath, @@ -193,6 +189,7 @@ export async function openFingerprintWindow(id: number) { if (!chromeInstance) { return; } + await sleep(1); await WindowDB.update(id, { status: 2, port: chromePort, diff --git a/packages/main/src/services/common-service.ts b/packages/main/src/services/common-service.ts index d9b3a84..42c0ea7 100644 --- a/packages/main/src/services/common-service.ts +++ b/packages/main/src/services/common-service.ts @@ -84,6 +84,7 @@ export const initCommonService = () => { ); ipcMain.handle('common-save-settings', async (_, values: SettingOptions) => { + const configFilePath = join(process.resourcesPath, 'chrome-power-config.json'); try { diff --git a/packages/main/src/utils/get-settings.ts b/packages/main/src/utils/get-settings.ts index 3d779cc..f90b863 100644 --- a/packages/main/src/utils/get-settings.ts +++ b/packages/main/src/utils/get-settings.ts @@ -1,12 +1,12 @@ import {existsSync, readFileSync, writeFileSync} from 'fs'; import {join} from 'path'; import type {SettingOptions} from '../../../shared/types/common'; -import {getChromePath} from '../fingerprint/device'; +import {getChromePath, getRootDir} from '../fingerprint/device'; export const getSettings = (): SettingOptions => { const configFilePath = join(process.resourcesPath, 'chrome-power-config.json'); let settings = { - profileCachePath: join(process.resourcesPath, 'chromePowerCache'), + profileCachePath: join(getRootDir(), 'chromePowerCache'), useLocalChrome: true, localChromePath: '', chromiumBinPath: '', diff --git a/scripts/uninstall.nsis b/scripts/uninstall.nsis new file mode 100644 index 0000000..e69de29