Skip to content

Commit 64f82bf

Browse files
author
Hiram
committed
fix path create error
1 parent 2c138b0 commit 64f82bf

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

electron/main/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,11 @@ app.whenReady().then(() => {
354354
});
355355

356356
showLoading();
357-
tmpDir('thumbnail');
357+
if (is.dev) {
358+
tmpDir( path.join(process.cwd(), 'thumbnail'));
359+
} else {
360+
tmpDir(path.join(appDataPath, 'thumbnail'));
361+
}
358362
createWindow();
359363
registerAppMenu();
360364

@@ -582,15 +586,26 @@ const getFolderSize = (folderPath: string): number => {
582586
};
583587

584588
const tmpDir = async(path: string) => {
585-
const pathExists = await fs.pathExistsSync(path);
586-
if (pathExists) {
587-
await fs.removeSync(path); // 删除文件, 不存在不会报错
589+
try {
590+
const pathExists = await fs.pathExistsSync(path);
591+
log.info(`[ipcMain] tmpDir: ${path}-exists-${pathExists}`);
592+
if (pathExists) {
593+
await fs.removeSync(path); // 删除文件, 不存在不会报错
594+
}
595+
await fs.emptyDirSync(path); // 清空目录, 不存在自动创建
596+
log.info(`[ipcMain] tmpDir: ${path}-created-sucess`);
597+
} catch (err) {
598+
log.error(err)
588599
}
589-
await fs.emptyDirSync(path); // 清空目录, 不存在自动创建
590600
};
591601

592602
ipcMain.on('tmpdir-manage', (event, action, trails) => {
593-
const formatPath = path.join(appDataPath, trails);
603+
let formatPath;
604+
if (is.dev) {
605+
formatPath = path.join(process.cwd(), trails);
606+
} else {
607+
formatPath = path.join(appDataPath, trails);
608+
}
594609
if (action === 'rmdir' || action === 'mkdir' || action === 'init') tmpDir(formatPath);
595610
if (action === 'size') event.reply("tmpdir-manage-size", getFolderSize(formatPath));
596611
});

0 commit comments

Comments
 (0)