Skip to content

Commit 3e5a393

Browse files
author
Hiram
committed
fix not mkdir thumbnail folder
1 parent b4ac475 commit 3e5a393

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/main/core/ipc.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@ import logger from './logger';
88
import { setting } from './db/service';
99
import puppeteerInElectron from '../utils/pie';
1010

11-
export const ipcListen = () => {
11+
12+
const tmpDir = async(path: string) => {
13+
try {
14+
const pathExists = await fs.pathExistsSync(path);
15+
logger.info(`[ipcMain] tmpDir: ${path}-exists-${pathExists}`);
16+
if (pathExists) {
17+
await fs.removeSync(path); // 删除文件, 不存在不会报错
18+
}
19+
await fs.emptyDirSync(path); // 清空目录, 不存在自动创建
20+
logger.info(`[ipcMain] tmpDir: ${path}-created-sucess`);
21+
} catch (err) {
22+
logger.error(err)
23+
}
24+
};
25+
26+
const ipcListen = () => {
1227
ipcMain.on('uninstallShortcut', () => {
1328
logger.info(`[ipcMain] globalShortcut unregisterAll`);
1429
globalShortcut.unregisterAll();
@@ -53,20 +68,6 @@ export const ipcListen = () => {
5368
return totalSize;
5469
};
5570

56-
const tmpDir = async(path: string) => {
57-
try {
58-
const pathExists = await fs.pathExistsSync(path);
59-
logger.info(`[ipcMain] tmpDir: ${path}-exists-${pathExists}`);
60-
if (pathExists) {
61-
await fs.removeSync(path); // 删除文件, 不存在不会报错
62-
}
63-
await fs.emptyDirSync(path); // 清空目录, 不存在自动创建
64-
logger.info(`[ipcMain] tmpDir: ${path}-created-sucess`);
65-
} catch (err) {
66-
logger.error(err)
67-
}
68-
};
69-
7071
ipcMain.on('tmpdir-manage', (event, action, trails) => {
7172
let formatPath;
7273
if (is.dev) {
@@ -139,4 +140,6 @@ export const ipcListen = () => {
139140
ipcMain.on('quit-app', () => {
140141
app.quit();
141142
});
142-
}
143+
}
144+
145+
export { ipcListen, tmpDir }

src/main/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import initServer from './core/server';
1111
import { init as dbInit} from './core/db';
1212
import { setting } from './core/db/service';
1313
import createMenu from './core/menu';
14-
import { ipcListen } from './core/ipc';
14+
import { ipcListen, tmpDir } from './core/ipc';
1515
import logger from './core/logger';
1616
import autoUpdater from './core/update';
1717
import createTray from './core/tray';
@@ -233,6 +233,11 @@ app.whenReady().then(async() => {
233233
optimizer.registerFramelessWindowIpc();
234234

235235
showLoading();
236+
if (is.dev) {
237+
tmpDir(join(process.cwd(), 'thumbnail'));
238+
} else {
239+
tmpDir(join(app.getPath('userData'), 'thumbnail'));
240+
}
236241
createWindow();
237242
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
238243
blocker.enableBlockingInSession(mainWindow.webContents.session);

0 commit comments

Comments
 (0)