Skip to content

Commit

Permalink
fix not mkdir thumbnail folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed Mar 1, 2024
1 parent b4ac475 commit 3e5a393
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
35 changes: 19 additions & 16 deletions src/main/core/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@ import logger from './logger';
import { setting } from './db/service';
import puppeteerInElectron from '../utils/pie';

export const ipcListen = () => {

const tmpDir = async(path: string) => {
try {
const pathExists = await fs.pathExistsSync(path);
logger.info(`[ipcMain] tmpDir: ${path}-exists-${pathExists}`);
if (pathExists) {
await fs.removeSync(path); // 删除文件, 不存在不会报错
}
await fs.emptyDirSync(path); // 清空目录, 不存在自动创建
logger.info(`[ipcMain] tmpDir: ${path}-created-sucess`);
} catch (err) {
logger.error(err)
}
};

const ipcListen = () => {
ipcMain.on('uninstallShortcut', () => {
logger.info(`[ipcMain] globalShortcut unregisterAll`);
globalShortcut.unregisterAll();
Expand Down Expand Up @@ -53,20 +68,6 @@ export const ipcListen = () => {
return totalSize;
};

const tmpDir = async(path: string) => {
try {
const pathExists = await fs.pathExistsSync(path);
logger.info(`[ipcMain] tmpDir: ${path}-exists-${pathExists}`);
if (pathExists) {
await fs.removeSync(path); // 删除文件, 不存在不会报错
}
await fs.emptyDirSync(path); // 清空目录, 不存在自动创建
logger.info(`[ipcMain] tmpDir: ${path}-created-sucess`);
} catch (err) {
logger.error(err)
}
};

ipcMain.on('tmpdir-manage', (event, action, trails) => {
let formatPath;
if (is.dev) {
Expand Down Expand Up @@ -139,4 +140,6 @@ export const ipcListen = () => {
ipcMain.on('quit-app', () => {
app.quit();
});
}
}

export { ipcListen, tmpDir }
7 changes: 6 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import initServer from './core/server';
import { init as dbInit} from './core/db';
import { setting } from './core/db/service';
import createMenu from './core/menu';
import { ipcListen } from './core/ipc';
import { ipcListen, tmpDir } from './core/ipc';
import logger from './core/logger';
import autoUpdater from './core/update';
import createTray from './core/tray';
Expand Down Expand Up @@ -233,6 +233,11 @@ app.whenReady().then(async() => {
optimizer.registerFramelessWindowIpc();

showLoading();
if (is.dev) {
tmpDir(join(process.cwd(), 'thumbnail'));
} else {
tmpDir(join(app.getPath('userData'), 'thumbnail'));
}
createWindow();
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
blocker.enableBlockingInSession(mainWindow.webContents.session);
Expand Down

0 comments on commit 3e5a393

Please sign in to comment.