🥅 处理异常,清除缓存后重启

This commit is contained in:
BTMuli
2025-11-15 14:50:46 +08:00
parent 2d0b409813
commit d74e7a7a31
2 changed files with 13 additions and 11 deletions

View File

@@ -166,7 +166,7 @@ import { emit } from "@tauri-apps/api/event";
import { open } from "@tauri-apps/plugin-dialog";
import { remove } from "@tauri-apps/plugin-fs";
import { platform } from "@tauri-apps/plugin-os";
import { exit } from "@tauri-apps/plugin-process";
import { relaunch } from "@tauri-apps/plugin-process";
import { backUpUserData, restoreUserData } from "@utils/dataBS.js";
import { getBuildTime } from "@utils/TGBuild.js";
import TGLogger from "@utils/TGLogger.js";
@@ -391,14 +391,18 @@ async function confirmDelCache(): Promise<void> {
}
await showLoading.start("正在清除缓存");
for (const dir of CacheDir) {
await showLoading.update(dir);
await remove(dir, { recursive: true });
try {
await showLoading.update(dir);
await remove(dir, { recursive: true });
} catch (e) {
await TGLogger.Error(`[Config][confirmDelCache] 清除缓存失败 ${dir} ${e}`);
}
}
await showLoading.end();
await TGLogger.Info("[Config][confirmDelCache] 缓存清除完成");
showSnackbar.success("缓存已清除!即将退出应用!");
await new Promise<void>((resolve) => setTimeout(resolve, 1500));
await exit();
await relaunch();
}
// 恢复默认设置

View File

@@ -1,7 +1,5 @@
/**
* @file utils/toolFunc.ts
* @description 一些工具函数
* @since Beta v0.8.2
* 一些工具函数
*/
import { AvatarExtResTypeEnum, AvatarExtTypeEnum } from "@enum/bbs.js";
@@ -122,14 +120,14 @@ export function bytesToSize(bytes: number): string {
}
/**
* @description 获取缓存目录
* @since Beta v0.5.0
* @returns {string|string[]} 缓存目录
* 获取缓存目录
* @returns {Array<string>|false} 缓存目录
*/
export async function getCacheDir(): Promise<string[] | false> {
export async function getCacheDir(): Promise<Array<string> | false> {
const cacheDir = await path.appCacheDir();
const osType = type().toLowerCase();
if (osType === "windows") {
// TODO: 会报错显示占用
const cache = `${cacheDir}${path.sep()}EBWebview${path.sep()}Default${path.sep()}Cache`;
const codeCache = `${cacheDir}${path.sep()}EBWebview${path.sep()}Default${path.sep()}Code Cache`;
return [cache, codeCache];