🌱 尝试缓存清除 #55

This commit is contained in:
BTMuli
2023-10-26 21:11:39 +08:00
parent 803705218b
commit 56c6c4f70f
3 changed files with 24 additions and 10 deletions

View File

@@ -13,7 +13,7 @@ edition = "2021"
tauri-build = { version = "1.4", features = [] } tauri-build = { version = "1.4", features = [] }
[dependencies] [dependencies]
tauri = { version = "1.4", features = [ "window-hide", "os-all", "clipboard-all", "dialog-open", "dialog-save", "fs-create-dir", "fs-remove-dir", "fs-write-file", "fs-remove-file", "fs-read-file", "path-all", "fs-exists", "window-close", "window-set-title", "window-unminimize", "window-show", "window-set-focus", "http-request", "shell-open"] } tauri = { version = "1.4", features = [ "process-relaunch", "window-hide", "os-all", "clipboard-all", "dialog-open", "dialog-save", "fs-create-dir", "fs-remove-dir", "fs-write-file", "fs-remove-file", "fs-read-file", "path-all", "fs-exists", "window-close", "window-set-title", "window-unminimize", "window-show", "window-set-focus", "http-request", "shell-open"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
webview2-com = "0.27.0" webview2-com = "0.27.0"

View File

@@ -54,6 +54,10 @@
}, },
"os": { "os": {
"all": true "all": true
},
"process": {
"all": false,
"relaunch": true
} }
}, },
"bundle": { "bundle": {

View File

@@ -122,7 +122,7 @@
/> />
</template> </template>
</v-list-item> </v-list-item>
<v-list-item prepend-icon="mdi-database-remove" title="清除用户缓存" @click="confirmDelUC" /> <v-list-item prepend-icon="mdi-database-remove" title="清除缓存" @click="confirmDelCache" />
<v-list-item <v-list-item
v-show="showReset" v-show="showReset"
title="重置数据库" title="重置数据库"
@@ -147,6 +147,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { app, fs, os } from "@tauri-apps/api"; import { app, fs, os } from "@tauri-apps/api";
import { relaunch } from "@tauri-apps/api/process";
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import showConfirm from "../../components/func/confirm"; import showConfirm from "../../components/func/confirm";
@@ -437,25 +438,34 @@ async function confirmUpdate(title?: string): Promise<void> {
} }
// 清除用户缓存 // 清除用户缓存
async function confirmDelUC(): Promise<void> { async function confirmDelCache(): Promise<void> {
const res = await showConfirm({ const res = await showConfirm({
title: "确认清除用户缓存吗?", title: "确认清除缓存吗?",
text: "备份数据也将被清除", text: "只删除 Webview 缓存,不处理用户数据",
}); });
if (!res) { if (!res) {
showSnackbar({ showSnackbar({
color: "grey", color: "grey",
text: "已取消清除用户缓存", text: "已取消清除缓存",
}); });
return; return;
} }
await fs.removeDir("userData", { await fs.removeDir("EBWebview\\Default\\Cache", {
dir: fs.BaseDirectory.AppLocalData, dir: fs.BaseDirectory.AppLocalData,
recursive: true, recursive: true,
}); });
showSnackbar({ text: "用户数据已删除!" }); await fs.removeDir("EBWebview\\Default\\Code Cache", {
achievementsStore.init(); dir: fs.BaseDirectory.AppLocalData,
await fs.createDir("userData", { dir: fs.BaseDirectory.AppLocalData }); recursive: true,
});
showSnackbar({
text: "缓存已清除!即将重启应用...",
});
await new Promise(() => {
setTimeout(async () => {
await relaunch();
}, 1500);
});
} }
// 恢复默认设置 // 恢复默认设置