🎨 一些调整

This commit is contained in:
目棃
2024-11-12 15:46:11 +08:00
parent d88e1d1429
commit eaa07601a5
2 changed files with 30 additions and 87 deletions

View File

@@ -283,25 +283,11 @@ async function getGachaLogs(pool: string, endId: string = "0", check?: string):
// 导入按钮点击事件 // 导入按钮点击事件
async function handleImportBtn(isV4: boolean): Promise<void> { async function handleImportBtn(isV4: boolean): Promise<void> {
if (isV4) { await TGLogger.Info(`[UserGacha][handleImportBtn] 导入祈愿数据${isV4 ? "(v4)" : ""}`);
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] 导入祈愿数据");
}
const selectedFile = await open({ const selectedFile = await open({
multiple: false, multiple: false,
title: "选择要导入的祈愿数据文件", title: "导入UIGF文件",
filters: [ filters: [{ name: "UIGF JSON", extensions: ["json"] }],
{
name: "UIGF JSON",
extensions: ["json"],
},
],
defaultPath: await path.downloadDir(), defaultPath: await path.downloadDir(),
directory: false, directory: false,
}); });
@@ -311,11 +297,8 @@ async function handleImportBtn(isV4: boolean): Promise<void> {
} }
const check = await verifyUigfData(selectedFile, isV4); const check = await verifyUigfData(selectedFile, isV4);
if (!check) return; if (!check) return;
if (isV4) { if (isV4) await importUigf4(selectedFile);
await importUigf4(selectedFile); else await importUigf(selectedFile);
} else {
await importUigf(selectedFile);
}
} }
// 导入 v4 版本的祈愿数据 // 导入 v4 版本的祈愿数据
@@ -393,13 +376,8 @@ async function exportUigf(): Promise<void> {
return; return;
} }
const file = await save({ const file = await save({
title: "选择导出祈愿数据的文件路径", title: "导出祈愿数据",
filters: [ filters: [{ name: "UIGF JSON", extensions: ["json"] }],
{
name: "UIGF JSON",
extensions: ["json"],
},
],
defaultPath: `${await path.downloadDir()}${path.sep()}UIGF_${uidCur.value}.json`, defaultPath: `${await path.downloadDir()}${path.sep()}UIGF_${uidCur.value}.json`,
}); });
if (!file) { if (!file) {

View File

@@ -1,7 +1,7 @@
/** /**
* @file utils/TGClient.ts * @file utils/TGClient.ts
* @desc 负责米游社客户端的 callback 处理 * @desc 负责米游社客户端的 callback 处理
* @since Beta v0.6.0 * @since Beta v0.6.3
*/ */
import { event, core, webviewWindow } from "@tauri-apps/api"; import { event, core, webviewWindow } from "@tauri-apps/api";
@@ -456,10 +456,7 @@ class TGClient {
try { try {
await windowFind.destroy(); await windowFind.destroy();
} catch (e) { } catch (e) {
showSnackbar({ showSnackbar({ text: `[TGClient][open] ${e}`, color: "error" });
text: `[TGClient][open] ${e}`,
color: "error",
});
await TGLogger.Error(`[TGClient][open] ${e}`); await TGLogger.Error(`[TGClient][open] ${e}`);
} }
} }
@@ -479,9 +476,7 @@ class TGClient {
this.route.pop(); this.route.pop();
if (this.route.length === 0) { if (this.route.length === 0) {
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client"); const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind != null) { if (windowFind != null) await windowFind.destroy();
await windowFind.destroy();
}
return; return;
} }
const url = this.route[this.route.length - 1]; const url = this.route[this.route.length - 1];
@@ -535,10 +530,7 @@ class TGClient {
): Promise<void> { ): Promise<void> {
const userStore = useUserStore(); const userStore = useUserStore();
if (!userStore.cookie) return; if (!userStore.cookie) return;
const cookie = { const cookie = { mid: userStore.cookie.mid, stoken: userStore.cookie.stoken };
mid: userStore.cookie.mid,
stoken: userStore.cookie.stoken,
};
const res = await TGRequest.User.getAuthkey2(cookie, arg.payload); const res = await TGRequest.User.getAuthkey2(cookie, arg.payload);
await this.callback(arg.callback, res.data); await this.callback(arg.callback, res.data);
} }
@@ -577,17 +569,13 @@ class TGClient {
async getCookieInfo(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> { async getCookieInfo(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> {
const user = useUserStore(); const user = useUserStore();
if (!user.cookie) return; if (!user.cookie) return;
const data = { const data = { ltoken: user.cookie.ltoken, ltuid: user.cookie.ltuid, login_ticket: "" };
ltoken: user.cookie.ltoken,
ltuid: user.cookie.ltuid,
login_ticket: "",
};
await this.callback(arg.callback, data); await this.callback(arg.callback, data);
} }
/** /**
* @func getCookieToken * @func getCookieToken
* @since Beta v0.5.5 * @since Beta v0.6.3
* @desc 获取米游社客户端的 cookie_token * @desc 获取米游社客户端的 cookie_token
* @param {TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetCookieTokenPayload>} arg - 请求参数 * @param {TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetCookieTokenPayload>} arg - 请求参数
* @returns {void} - 无返回值 * @returns {void} - 无返回值
@@ -599,34 +587,25 @@ class TGClient {
if (!user.cookie) return; if (!user.cookie) return;
if (arg.payload.forceRefresh) { if (arg.payload.forceRefresh) {
const res = await getCookieTokenBySToken(user.cookie.mid, user.cookie.stoken); const res = await getCookieTokenBySToken(user.cookie.mid, user.cookie.stoken);
if (typeof res !== "string") { if (typeof res !== "string") return;
return;
}
user.cookie.cookie_token = res; user.cookie.cookie_token = res;
await TGSqlite.saveAppData("cookie", JSON.stringify(user.cookie)); await TGSqlite.saveAppData("cookie", JSON.stringify(user.cookie));
} }
// todo 优化代码
const executeJS = `javascript:(function(){ const executeJS = `javascript:(function(){
let domainCur = window.location.hostname; let domainCur = window.location.hostname;
if(domainCur.endsWith('.miyoushe.com')) { if (domainCur.endsWith('.miyoushe.com')) domainCur = '.miyoushe.com';
domainCur = '.miyoushe.com'; else domainCur = '.mihoyo.com';
} else { document.cookie = 'account_id=${user.cookie!.account_id}; domain=' + domainCur + '; path=/; max-age=31536000';
domainCur = '.mihoyo.com'; 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 = "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=/; max-age=31536000';
document.cookie = "cookie_token=${user.cookie.cookie_token};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; document.cookie = 'ltmid_v2=${user.cookie!.mid}; domain=' + domainCur + '; path=/; max-age=31536000';
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=/; max-age=31536000';
document.cookie = "ltoken=${user.cookie.ltoken};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"; document.cookie = 'ltuid_v2=${user.cookie!.ltuid}; domain=' + domainCur + '; path=/; max-age=31536000';
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;";
})();`; })();`;
console.info(`[getCookieToken] ${executeJS}`); console.info(`[getCookieToken] ${executeJS}`);
await core.invoke("execute_js", { label: "mhy_client", js: executeJS }); await core.invoke("execute_js", { label: "mhy_client", js: executeJS });
const data = { const data = { cookie_token: user.cookie.cookie_token };
cookie_token: user.cookie.cookie_token,
};
await this.callback(arg.callback, data); await this.callback(arg.callback, data);
} }
@@ -638,9 +617,7 @@ class TGClient {
* @returns {void} - 无返回值 * @returns {void} - 无返回值
*/ */
async getDS(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> { async getDS(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> {
const data = { const data = { DS: getDS4JS("lk2", 1, undefined, undefined) };
DS: getDS4JS("lk2", 1, undefined, undefined),
};
await this.callback(arg.callback, data); await this.callback(arg.callback, data);
} }
@@ -691,9 +668,7 @@ class TGClient {
* @returns {void} - 无返回值 * @returns {void} - 无返回值
*/ */
async getStatusBarHeight(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> { async getStatusBarHeight(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> {
const data = { const data = { statusBarHeight: 0 };
statusBarHeight: 0,
};
await this.callback(arg.callback, data); await this.callback(arg.callback, data);
} }
@@ -750,15 +725,9 @@ class TGClient {
text: `不支持的操作OpenApplication(${JSON.stringify(arg.payload)})`, text: `不支持的操作OpenApplication(${JSON.stringify(arg.payload)})`,
color: "error", color: "error",
}); });
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => setTimeout(() => resolve(), 1500));
setTimeout(() => {
resolve();
}, 1500);
});
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client"); const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind !== null) { if (windowFind !== null) await windowFind.setFocus();
await windowFind.setFocus();
}
} }
/** /**
@@ -792,11 +761,7 @@ class TGClient {
if (appWindow != null) { if (appWindow != null) {
await appWindow.setFocus(); await appWindow.setFocus();
} }
showSnackbar({ showSnackbar({ text: `未知链接:${arg.payload.page}`, color: "error", timeout: 3000 });
text: `未知链接:${arg.payload.page}`,
color: "error",
timeout: 3000,
});
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
setTimeout(() => { setTimeout(() => {
resolve(); resolve();