Skip to content

Commit

Permalink
处理缓存路径,避免卸载程序后清理 chrome/chromium 缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
niuniuland committed Mar 22, 2024
1 parent 2ee47a6 commit 74a8e5a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = async function () {
allowToChangeInstallationDirectory: true,
createDesktopShortcut: true,
createStartMenuShortcut: true,
shortcutName: 'chrome-power',
shortcutName: 'chrome-power-alpha',
},

win: {
Expand Down
9 changes: 9 additions & 0 deletions packages/main/src/fingerprint/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
9 changes: 3 additions & 6 deletions packages/main/src/fingerprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -193,6 +189,7 @@ export async function openFingerprintWindow(id: number) {
if (!chromeInstance) {
return;
}
await sleep(1);
await WindowDB.update(id, {
status: 2,
port: chromePort,
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/services/common-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/utils/get-settings.ts
Original file line number Diff line number Diff line change
@@ -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: '',
Expand Down
Empty file added scripts/uninstall.nsis
Empty file.

0 comments on commit 74a8e5a

Please sign in to comment.