Skip to content

Commit

Permalink
♻️ showSnackbar重构
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Nov 14, 2024
1 parent 20b9631 commit ac6dbe0
Show file tree
Hide file tree
Showing 69 changed files with 613 additions and 1,097 deletions.
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

File renamed without changes.
25 changes: 10 additions & 15 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ onBeforeMount(async () => {
async function checkResize(): Promise<void> {
const screen = await TauriWindow.currentMonitor();
if (screen === null) {
showSnackbar({ text: "获取屏幕信息失败!", color: "error", timeout: 3000 });
showSnackbar.error("获取屏幕信息失败!", 3000);
return;
}
const windowCur = await webviewWindow.getCurrentWebviewWindow();
Expand Down Expand Up @@ -153,7 +153,7 @@ async function checkUserLoad(): Promise<void> {
// 检测用户数据
const uidDB = await TSUserAccount.account.getAllUid();
if (uidDB.length === 0 && appStore.isLogin) {
showSnackbar({ text: "未检测到可用UID,请重新登录!", color: "warn" });
showSnackbar.warn("未检测到可用UID,请重新登录");
appStore.isLogin = false;
return;
}
Expand All @@ -164,7 +164,7 @@ async function checkUserLoad(): Promise<void> {
}
const curAccount = await TSUserAccount.account.getAccount(userStore.uid.value);
if (curAccount === false) {
showSnackbar({ text: `未获取到${userStore.uid.value}账号数据`, color: "error" });
showSnackbar.error(`未获取到${userStore.uid.value}的账号数据!`);
await TGLogger.Error(`[App][listenOnInit] 获取${userStore.uid.value}账号数据失败`);
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
Expand All @@ -173,7 +173,7 @@ async function checkUserLoad(): Promise<void> {
}
const curGameAccount = await TSUserAccount.game.getCurAccount(userStore.uid.value);
if (curGameAccount === false) {
showSnackbar({ text: `未获取到${userStore.uid.value}游戏数据`, color: "error" });
showSnackbar.error(`未获取到${userStore.uid.value}的游戏数据!`);
await TGLogger.Error(`[App][listenOnInit] 获取${userStore.uid.value}游戏数据失败`);
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
Expand All @@ -184,13 +184,11 @@ async function checkUserLoad(): Promise<void> {
async function getDeepLink(): Promise<UnlistenFn> {
return await event.listen("active_deep_link", async (e: Event<string>) => {
const windowGet = new webviewWindow.WebviewWindow("TeyvatGuide");
if (await windowGet.isMinimized()) {
await windowGet.unminimize();
}
if (await windowGet.isMinimized()) await windowGet.unminimize();
await windowGet.setFocus();
const payload = parseDeepLink(e.payload);
if (payload === false) {
showSnackbar({ text: "无效的 deep link!", color: "error", timeout: 3000 });
showSnackbar.error("无效的 deep link!", 3000);
await TGLogger.Error(`[App][getDeepLink] 无效的 deep link! ${JSON.stringify(e.payload)}`);
return;
}
Expand Down Expand Up @@ -224,7 +222,7 @@ async function handleDeepLink(payload: string): Promise<void> {
if (payload.startsWith("router?path=")) {
const routerPath = payload.replace("router?path=", "");
if (router.currentRoute.value.path === routerPath) {
showSnackbar({ text: "已在当前页面!", color: "warn", timeout: 3000 });
showSnackbar.warn("已在当前页面!", 3000);
return;
}
await router.push(routerPath);
Expand All @@ -244,6 +242,7 @@ async function toUIAF(link: string) {
// 检测更新
async function checkUpdate(): Promise<void> {
// @ts-expect-error-next-line
const isProdEnv = import.meta.env.MODE === "production";
const needUpdate = await TGSqlite.checkUpdate();
if (needUpdate && isProdEnv) {
Expand All @@ -253,16 +252,12 @@ async function checkUpdate(): Promise<void> {
text: "是否更新数据库数据?(请确保成就数据已导出)",
});
if (!confirm) {
showSnackbar({
text: "请到设置页手动更新数据库!",
color: "error",
timeout: 3000,
});
showSnackbar.error("请到设置页手动更新数据库!", 3000);
return;
}
appStore.buildTime = getBuildTime();
await TGSqlite.update();
showSnackbar({ text: "数据库已更新!", color: "success", timeout: 3000 });
showSnackbar.success("数据库已更新!", 3000);
window.open("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/app/t-pinWin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ onMounted(async () => {
async function switchPin(): Promise<void> {
isPined.value = !isPined.value;
await getCurrentWindow().setAlwaysOnTop(isPined.value);
const text = isPined.value ? "已将窗口置顶!" : "已经取消窗口置顶!";
showSnackbar({ text: text, color: "success" });
showSnackbar.success(isPined.value ? "已将窗口置顶!" : "已经取消窗口置顶!");
}
</script>
<style lang="css" scoped>
Expand Down
62 changes: 30 additions & 32 deletions src/components/config/tc-dataDir.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</template>
<template #append>
<div class="config-opers">
<v-icon @click="confirmCUD()" title="修改用户数据目录"> mdi-pencil </v-icon>
<v-icon @click="openPath('user')" title="打开用户数据目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('user')" title="复制用户数据目录路径"> mdi-content-copy </v-icon>
<v-icon @click="confirmCUD()" title="修改用户数据目录"> mdi-pencil</v-icon>
<v-icon @click="openPath('user')" title="打开用户数据目录"> mdi-folder-open</v-icon>
<v-icon @click="copyPath('user')" title="复制用户数据目录路径"> mdi-content-copy</v-icon>
</div>
</template>
</v-list-item>
Expand All @@ -24,8 +24,8 @@
</template>
<template #append>
<div class="config-opers">
<v-icon @click="openPath('db')" title="打开数据库目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('db')" title="复制数据库目录路径"> mdi-content-copy </v-icon>
<v-icon @click="openPath('db')" title="打开数据库目录"> mdi-folder-open</v-icon>
<v-icon @click="copyPath('db')" title="复制数据库目录路径"> mdi-content-copy</v-icon>
</div>
</template>
</v-list-item>
Expand All @@ -41,9 +41,9 @@
</template>
<template #append>
<div class="config-opers">
<v-icon @click="confirmCGD()" title="修改游戏安装目录"> mdi-pencil </v-icon>
<v-icon @click="openPath('game')" title="打开游戏安装目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('game')" title="复制游戏安装目录"> mdi-content-copy </v-icon>
<v-icon @click="confirmCGD()" title="修改游戏安装目录"> mdi-pencil</v-icon>
<v-icon @click="openPath('game')" title="打开游戏安装目录"> mdi-folder-open</v-icon>
<v-icon @click="copyPath('game')" title="复制游戏安装目录"> mdi-content-copy</v-icon>
</div>
</template>
</v-list-item>
Expand All @@ -55,9 +55,9 @@
</template>
<template #append>
<div class="config-opers">
<v-icon @click="confirmCLD()" title="清理日志文件"> mdi-delete </v-icon>
<v-icon @click="openPath('log')" title="打开日志目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('log')" title="复制日志目录路径"> mdi-content-copy </v-icon>
<v-icon @click="confirmCLD()" title="清理日志文件"> mdi-delete</v-icon>
<v-icon @click="openPath('log')" title="打开日志目录"> mdi-folder-open</v-icon>
<v-icon @click="copyPath('log')" title="复制日志目录路径"> mdi-content-copy</v-icon>
</div>
</template>
</v-list-item>
Expand Down Expand Up @@ -94,15 +94,15 @@ onMounted(async () => {
message += "日志路径 ";
}
if (message !== "") {
showSnackbar({ text: `${message}已更新!`, color: "success" });
showSnackbar.success(`${message}已更新!`);
}
});
async function confirmCUD(): Promise<void> {
const oriDir = appStore.userDir.value;
const check = await showConfirm({ title: "确认修改用户数据路径吗?" });
if (!check) {
showSnackbar({ color: "cancel", text: "已取消修改" });
showSnackbar.cancel("已取消修改");
return;
}
const dir: string | null = await open({
Expand All @@ -111,30 +111,28 @@ async function confirmCUD(): Promise<void> {
multiple: false,
});
if (dir === null) {
showSnackbar({ color: "error", text: "路径不能为空!" });
showSnackbar.warn("路径不能为空!");
return;
}
if (dir === oriDir) {
showSnackbar({ color: "warn", text: "路径未修改!" });
showSnackbar.warn("路径未修改!");
return;
}
appStore.userDir.value = dir;
await TGSqlite.saveAppData("userDir", dir);
await backUpUserData(dir);
showSnackbar({ text: "已重新备份数据!", color: "success" });
showSnackbar.success("已修改用户数据路径!");
const confirm = await showConfirm({ title: "是否删除原用户数据目录?", text: "删除后不可恢复!" });
if (confirm) {
await remove(oriDir, { recursive: true });
showSnackbar({ text: "已删除原用户数据目录!", color: "success" });
showSnackbar.success("已删除原用户数据目录!");
}
setTimeout(() => {
window.location.reload();
}, 4000);
setTimeout(() => window.location.reload(), 4000);
}
async function confirmCGD(): Promise<void> {
if (platform() !== "windows") {
showSnackbar({ text: "不支持的平台!", color: "warning" });
showSnackbar.warn("不支持的平台!");
return;
}
const oriEmpty = appStore.gameDir.value === "未设置";
Expand All @@ -143,7 +141,7 @@ async function confirmCGD(): Promise<void> {
text: oriEmpty ? "请选择启动器所在目录" : `当前:${appStore.gameDir.value}`,
});
if (!editConfirm) {
showSnackbar({ text: oriEmpty ? "取消设置启动器目录" : "取消修改启动器目录", color: "cancel" });
showSnackbar.cancel(oriEmpty ? "已取消设置" : "已取消修改");
return;
}
const dir: string | null = await open({
Expand All @@ -152,20 +150,20 @@ async function confirmCGD(): Promise<void> {
multiple: false,
});
if (dir === null) {
showSnackbar({ text: "路径不能为空!", color: "error" });
showSnackbar.warn("路径不能为空!");
return;
}
if (!oriEmpty && appStore.gameDir.value === dir) {
showSnackbar({ text: "路径未修改!", color: "warn" });
showSnackbar.warn("路径未修改!");
return;
}
// 校验是否存在游戏本体
if (!(await exists(`${dir}${path.sep()}YuanShen.exe`))) {
showSnackbar({ text: "未检测到游戏本体", color: "error" });
showSnackbar.warn("未检测到游戏本体");
return;
}
appStore.gameDir.value = dir;
showSnackbar({ text: oriEmpty ? "成功设置游戏目录" : "成功修改游戏目录" });
showSnackbar.success(oriEmpty ? "成功设置游戏目录" : "成功修改游戏目录");
}
// 判断是否超过一周
Expand All @@ -182,7 +180,7 @@ async function confirmCLD(): Promise<void> {
text: "将保留一周内的日志文件",
});
if (!check) {
showSnackbar({ color: "cancel", text: "已取消清理" });
showSnackbar.cancel("已取消清理");
return;
}
const logDir = appStore.logDir.value;
Expand All @@ -196,14 +194,14 @@ async function confirmCLD(): Promise<void> {
return isOverWeek(date);
});
if (delFiles.length < 1) {
showSnackbar({ color: "warn", text: "无需清理!" });
showSnackbar.warn("无需清理!");
return;
}
for (const file of delFiles) {
const filePath = `${logDir}/${file.name}`;
await remove(filePath);
}
showSnackbar({ text: `已清理 ${delFiles.length} 个日志文件!` });
showSnackbar.success(`已清理 ${delFiles.length} 个日志文件!`);
}
function copyPath(type: "db" | "user" | "log" | "game"): void {
Expand All @@ -223,14 +221,14 @@ function copyPath(type: "db" | "user" | "log" | "game"): void {
break;
case "game":
if (appStore.gameDir.value === "未设置") {
showSnackbar({ text: "未设置游戏目录!", color: "warn" });
showSnackbar.warn("未设置游戏目录!");
return;
}
targetPath = appStore.gameDir.value;
targetName = "游戏安装目录";
}
navigator.clipboard.writeText(targetPath);
showSnackbar({ text: `${targetName}路径已复制!` });
showSnackbar.success(`${targetName}路径已复制!`);
}
async function openPath(type: "db" | "user" | "log" | "game"): Promise<void> {
Expand All @@ -247,7 +245,7 @@ async function openPath(type: "db" | "user" | "log" | "game"): Promise<void> {
break;
case "game":
if (appStore.gameDir.value === "未设置") {
showSnackbar({ text: "未设置游戏目录!", color: "warn" });
showSnackbar.warn("未设置游戏目录!");
return;
}
targetPath = appStore.gameDir.value;
Expand Down
14 changes: 7 additions & 7 deletions src/components/config/tc-gameBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@ const account = computed<TGApp.Sqlite.Account.Game>(() => userStore.account.valu
async function tryPlayGame(): Promise<void> {
if (!userStore.uid.value || !userStore.cookie.value) {
showSnackbar({ text: "请先登录!", color: "warn" });
showSnackbar.warn("请先登录!");
return;
}
if (account.value.isOfficial === 0) {
showSnackbar({ text: "仅支持官服用户启动!", color: "warn" });
showSnackbar.warn("仅支持官服用户启动!");
return;
}
if (appStore.gameDir.value === "未设置") {
showSnackbar({ text: "未设置游戏安装目录!", color: "warn" });
showSnackbar.warn("未设置游戏安装目录!");
return;
}
const gamePath = `${appStore.gameDir.value}${path.sep()}YuanShen.exe`;
if (!(await exists(gamePath))) {
showSnackbar({ text: "未检测到原神本体应用!", color: "warn" });
showSnackbar.warn("未检测到原神本体应用!");
return;
}
const resp = await TGRequest.User.getAuthTicket(account.value, userStore.cookie.value);
if (typeof resp !== "string") {
showSnackbar({ text: `[${resp.retcode}] ${resp.message}`, color: "error" });
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Error(
`[config][gameBadge] 尝试获取authTicket失败,当前用户:${account.value.uid}-${account.value.gameUid}`,
);
await TGLogger.Error(`[config][gameBadge] resp: ${JSON.stringify(resp)}`);
return;
}
showSnackbar({ text: `成功获取ticket:${resp},正在启动应用...` });
showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`);
const cmd = Command.create("exec-sh", [`&"${gamePath}" login_auth_ticket=${resp}`], {
cwd: appStore.gameDir.value,
encoding: "utf-8",
Expand All @@ -69,7 +69,7 @@ async function tryPlayGame(): Promise<void> {
if (result.stderr) {
await TGLogger.Error(`[config][gameBadge] 启动游戏本体失败!`);
console.error(result.stderr);
showSnackbar({ text: `[config][gameBadge] ${result.stderr}`, color: "error" });
showSnackbar.error(`[${result.code}] ${result.stderr}`);
}
}
</script>
Expand Down
5 changes: 1 addition & 4 deletions src/components/config/tc-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ onMounted(async () => {
try {
dbInfo.value = await TGSqlite.getAppData();
} catch (e) {
showSnackbar({
text: "加载数据库错误,请重置数据库!",
color: "error",
});
showSnackbar.warn("加载数据库错误,请重置数据库!");
await TGLogger.Error(`加载数据库错误: ${e}`);
}
});
Expand Down
Loading

0 comments on commit ac6dbe0

Please sign in to comment.