Skip to content

Commit

Permalink
⚡️ 自动检测 ck 并获取数据 #99
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Mar 12, 2024
1 parent 8bf7459 commit 351c865
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/config/tc-userBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ async function getTokenWeb(cookie: string): Promise<void> {
text: "登录成功!",
color: "success",
});
console.log("cookieUser", cookieUser);
}
async function refreshUser() {
Expand Down
31 changes: 29 additions & 2 deletions src/utils/TGClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,30 @@ class TGClient {
await invoke("execute_js", { label: "mhy_client", js: executeJS });
}

/**
* @func loadSignIn
* @since Beta v0.4.4
* @desc 自动检测登录ck
* @returns {Promise<void>}
*/
async loadSignIn(): Promise<void> {
const executeJS = `javascript:(async function() {
let isLogin = false;
while(!isLogin) {
var ck = document.cookie;
if(ck.includes("login_ticket")) {
const arg = {
method: 'teyvat_sign_in',
payload: ck,
}
await window.__TAURI__.event.emit('post_mhy_client',JSON.stringify(arg));
isLogin = true;
}
}
})();`;
await invoke("execute_js", { label: "mhy_client", js: executeJS });
}

/**
* @func nullCallback
* @since Beta v0.3.9
Expand All @@ -453,7 +477,7 @@ class TGClient {

/**
* @func open
* @since Beta v0.4.3
* @since Beta v0.4.4
* @desc 打开米游社客户端
* @param {string} func - 方法名
* @param {string} url - url
Expand All @@ -468,6 +492,9 @@ class TGClient {
await this.window?.show();
await this.window?.setFocus();
await this.loadJSBridge();
if (func === "config_sign_in") {
await this.loadSignIn();
}
}

/* JSBridge 回调处理 */
Expand Down Expand Up @@ -669,7 +696,7 @@ class TGClient {
}
const data = {
"user-agent": TGConstant.BBS.UA_MOBILE,
"x-rpc-client_type": "5",
"x-rpc-client_type": "2",
"x-rpc-device_id": deviceInfo.device_id,
"x-rpc-app_version": TGConstant.BBS.VERSION,
"x-rpc-device_fp": deviceInfo.device_fp,
Expand Down

0 comments on commit 351c865

Please sign in to comment.