diff --git a/src/pages/common/PageConfig.vue b/src/pages/common/PageConfig.vue index 932334b1..163698d2 100644 --- a/src/pages/common/PageConfig.vue +++ b/src/pages/common/PageConfig.vue @@ -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 { } 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((resolve) => setTimeout(resolve, 1500)); - await exit(); + await relaunch(); } // 恢复默认设置 diff --git a/src/utils/toolFunc.ts b/src/utils/toolFunc.ts index bd94c2f9..0a7d15b5 100644 --- a/src/utils/toolFunc.ts +++ b/src/utils/toolFunc.ts @@ -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|false} 缓存目录 */ -export async function getCacheDir(): Promise { +export async function getCacheDir(): Promise | 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];