Skip to content

Commit

Permalink
🎨 一些调整
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Nov 12, 2024
1 parent d88e1d1 commit eaa0760
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 87 deletions.
36 changes: 7 additions & 29 deletions src/pages/User/Gacha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,11 @@ async function getGachaLogs(pool: string, endId: string = "0", check?: string):
// 导入按钮点击事件
async function handleImportBtn(isV4: boolean): Promise<void> {
if (isV4) {
const checkConfirm = await showConfirm({ title: "确定导入UIGFv4格式的祈愿数据?" });
if (!checkConfirm) {
showSnackbar({ color: "cancel", text: "已取消 UIGF v4 格式导入" });
return;
}
await TGLogger.Info("[UserGacha][handleImportBtn] 导入祈愿数据(v4)");
} else {
await TGLogger.Info("[UserGacha][handleImportBtn] 导入祈愿数据");
}
await TGLogger.Info(`[UserGacha][handleImportBtn] 导入祈愿数据${isV4 ? "(v4)" : ""}`);
const selectedFile = await open({
multiple: false,
title: "选择要导入的祈愿数据文件",
filters: [
{
name: "UIGF JSON",
extensions: ["json"],
},
],
title: "导入UIGF文件",
filters: [{ name: "UIGF JSON", extensions: ["json"] }],
defaultPath: await path.downloadDir(),
directory: false,
});
Expand All @@ -311,11 +297,8 @@ async function handleImportBtn(isV4: boolean): Promise<void> {
}
const check = await verifyUigfData(selectedFile, isV4);
if (!check) return;
if (isV4) {
await importUigf4(selectedFile);
} else {
await importUigf(selectedFile);
}
if (isV4) await importUigf4(selectedFile);
else await importUigf(selectedFile);
}
// 导入 v4 版本的祈愿数据
Expand Down Expand Up @@ -393,13 +376,8 @@ async function exportUigf(): Promise<void> {
return;
}
const file = await save({
title: "选择导出祈愿数据的文件路径",
filters: [
{
name: "UIGF JSON",
extensions: ["json"],
},
],
title: "导出祈愿数据",
filters: [{ name: "UIGF JSON", extensions: ["json"] }],
defaultPath: `${await path.downloadDir()}${path.sep()}UIGF_${uidCur.value}.json`,
});
if (!file) {
Expand Down
81 changes: 23 additions & 58 deletions src/utils/TGClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file utils/TGClient.ts
* @desc 负责米游社客户端的 callback 处理
* @since Beta v0.6.0
* @since Beta v0.6.3
*/

import { event, core, webviewWindow } from "@tauri-apps/api";
Expand Down Expand Up @@ -456,10 +456,7 @@ class TGClient {
try {
await windowFind.destroy();
} catch (e) {
showSnackbar({
text: `[TGClient][open] ${e}`,
color: "error",
});
showSnackbar({ text: `[TGClient][open] ${e}`, color: "error" });
await TGLogger.Error(`[TGClient][open] ${e}`);
}
}
Expand All @@ -479,9 +476,7 @@ class TGClient {
this.route.pop();
if (this.route.length === 0) {
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind != null) {
await windowFind.destroy();
}
if (windowFind != null) await windowFind.destroy();
return;
}
const url = this.route[this.route.length - 1];
Expand Down Expand Up @@ -535,10 +530,7 @@ class TGClient {
): Promise<void> {
const userStore = useUserStore();
if (!userStore.cookie) return;
const cookie = {
mid: userStore.cookie.mid,
stoken: userStore.cookie.stoken,
};
const cookie = { mid: userStore.cookie.mid, stoken: userStore.cookie.stoken };
const res = await TGRequest.User.getAuthkey2(cookie, arg.payload);
await this.callback(arg.callback, res.data);
}
Expand Down Expand Up @@ -577,17 +569,13 @@ class TGClient {
async getCookieInfo(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> {
const user = useUserStore();
if (!user.cookie) return;
const data = {
ltoken: user.cookie.ltoken,
ltuid: user.cookie.ltuid,
login_ticket: "",
};
const data = { ltoken: user.cookie.ltoken, ltuid: user.cookie.ltuid, login_ticket: "" };
await this.callback(arg.callback, data);
}

/**
* @func getCookieToken
* @since Beta v0.5.5
* @since Beta v0.6.3
* @desc 获取米游社客户端的 cookie_token
* @param {TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetCookieTokenPayload>} arg - 请求参数
* @returns {void} - 无返回值
Expand All @@ -599,34 +587,25 @@ class TGClient {
if (!user.cookie) return;
if (arg.payload.forceRefresh) {
const res = await getCookieTokenBySToken(user.cookie.mid, user.cookie.stoken);
if (typeof res !== "string") {
return;
}
if (typeof res !== "string") return;
user.cookie.cookie_token = res;
await TGSqlite.saveAppData("cookie", JSON.stringify(user.cookie));
}
// todo 优化代码
const executeJS = `javascript:(function(){
let domainCur = window.location.hostname;
if(domainCur.endsWith('.miyoushe.com')) {
domainCur = '.miyoushe.com';
} else {
domainCur = '.mihoyo.com';
}
document.cookie = "account_id_v2=${user.cookie.account_id};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "cookie_token=${user.cookie.cookie_token};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltoken=${user.cookie.ltoken};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "account_id=${user.cookie.account_id};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "account_mid_v2=${user.cookie.mid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltmid_v2=${user.cookie.mid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
let domainCur = window.location.hostname;
if (domainCur.endsWith('.miyoushe.com')) domainCur = '.miyoushe.com';
else domainCur = '.mihoyo.com';
document.cookie = 'account_id=${user.cookie!.account_id}; domain=' + domainCur + '; path=/; max-age=31536000';
document.cookie = 'account_id_v2=${user.cookie!.account_id}; domain=' + domainCur + '; path=/; max-age=31536000';
document.cookie = 'account_mid_v2=${user.cookie!.mid}; domain=' + domainCur + '; path=/; max-age=31536000';
document.cookie = 'cookie_token=${user.cookie!.cookie_token}; domain=' + domainCur + '; path=/; max-age=31536000';
document.cookie = 'ltmid_v2=${user.cookie!.mid}; domain=' + domainCur + '; path=/; max-age=31536000';
document.cookie = 'ltoken=${user.cookie!.ltoken}; domain=' + domainCur + '; path=/; max-age=31536000';
document.cookie = 'ltuid_v2=${user.cookie!.ltuid}; domain=' + domainCur + '; path=/; max-age=31536000';
})();`;
console.info(`[getCookieToken] ${executeJS}`);
await core.invoke("execute_js", { label: "mhy_client", js: executeJS });
const data = {
cookie_token: user.cookie.cookie_token,
};
const data = { cookie_token: user.cookie.cookie_token };
await this.callback(arg.callback, data);
}

Expand All @@ -638,9 +617,7 @@ class TGClient {
* @returns {void} - 无返回值
*/
async getDS(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> {
const data = {
DS: getDS4JS("lk2", 1, undefined, undefined),
};
const data = { DS: getDS4JS("lk2", 1, undefined, undefined) };
await this.callback(arg.callback, data);
}

Expand Down Expand Up @@ -691,9 +668,7 @@ class TGClient {
* @returns {void} - 无返回值
*/
async getStatusBarHeight(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> {
const data = {
statusBarHeight: 0,
};
const data = { statusBarHeight: 0 };
await this.callback(arg.callback, data);
}

Expand Down Expand Up @@ -750,15 +725,9 @@ class TGClient {
text: `不支持的操作:OpenApplication(${JSON.stringify(arg.payload)})`,
color: "error",
});
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 1500);
});
await new Promise<void>((resolve) => setTimeout(() => resolve(), 1500));
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind !== null) {
await windowFind.setFocus();
}
if (windowFind !== null) await windowFind.setFocus();
}

/**
Expand Down Expand Up @@ -792,11 +761,7 @@ class TGClient {
if (appWindow != null) {
await appWindow.setFocus();
}
showSnackbar({
text: `未知链接:${arg.payload.page}`,
color: "error",
timeout: 3000,
});
showSnackbar({ text: `未知链接:${arg.payload.page}`, color: "error", timeout: 3000 });
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
Expand Down

0 comments on commit eaa0760

Please sign in to comment.