Skip to content

Commit d74e7a7

Browse files
committed
🥅 处理异常,清除缓存后重启
1 parent 2d0b409 commit d74e7a7

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/pages/common/PageConfig.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ import { emit } from "@tauri-apps/api/event";
166166
import { open } from "@tauri-apps/plugin-dialog";
167167
import { remove } from "@tauri-apps/plugin-fs";
168168
import { platform } from "@tauri-apps/plugin-os";
169-
import { exit } from "@tauri-apps/plugin-process";
169+
import { relaunch } from "@tauri-apps/plugin-process";
170170
import { backUpUserData, restoreUserData } from "@utils/dataBS.js";
171171
import { getBuildTime } from "@utils/TGBuild.js";
172172
import TGLogger from "@utils/TGLogger.js";
@@ -391,14 +391,18 @@ async function confirmDelCache(): Promise<void> {
391391
}
392392
await showLoading.start("正在清除缓存");
393393
for (const dir of CacheDir) {
394-
await showLoading.update(dir);
395-
await remove(dir, { recursive: true });
394+
try {
395+
await showLoading.update(dir);
396+
await remove(dir, { recursive: true });
397+
} catch (e) {
398+
await TGLogger.Error(`[Config][confirmDelCache] 清除缓存失败 ${dir} ${e}`);
399+
}
396400
}
397401
await showLoading.end();
398402
await TGLogger.Info("[Config][confirmDelCache] 缓存清除完成");
399403
showSnackbar.success("缓存已清除!即将退出应用!");
400404
await new Promise<void>((resolve) => setTimeout(resolve, 1500));
401-
await exit();
405+
await relaunch();
402406
}
403407
404408
// 恢复默认设置

src/utils/toolFunc.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
2-
* @file utils/toolFunc.ts
3-
* @description 一些工具函数
4-
* @since Beta v0.8.2
2+
* 一些工具函数
53
*/
64

75
import { AvatarExtResTypeEnum, AvatarExtTypeEnum } from "@enum/bbs.js";
@@ -122,14 +120,14 @@ export function bytesToSize(bytes: number): string {
122120
}
123121

124122
/**
125-
* @description 获取缓存目录
126-
* @since Beta v0.5.0
127-
* @returns {string|string[]} 缓存目录
123+
* 获取缓存目录
124+
* @returns {Array<string>|false} 缓存目录
128125
*/
129-
export async function getCacheDir(): Promise<string[] | false> {
126+
export async function getCacheDir(): Promise<Array<string> | false> {
130127
const cacheDir = await path.appCacheDir();
131128
const osType = type().toLowerCase();
132129
if (osType === "windows") {
130+
// TODO: 会报错显示占用
133131
const cache = `${cacheDir}${path.sep()}EBWebview${path.sep()}Default${path.sep()}Cache`;
134132
const codeCache = `${cacheDir}${path.sep()}EBWebview${path.sep()}Default${path.sep()}Code Cache`;
135133
return [cache, codeCache];

0 commit comments

Comments
 (0)