From ac25685fbddfbdb727b890685db6d04b2ce79489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Thu, 1 Feb 2024 11:20:53 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E6=AD=A3=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E7=99=BB=E5=BD=95=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #89 --- src-tauri/src/client.rs | 29 +++- src-tauri/tauri.conf.json | 5 + src/components/config/tc-userBadge.vue | 173 +++++++++++++++++++++++- src/components/overlay/to-gameLogin.vue | 43 +++--- src/plugins/Mys/request/doGameLogin.ts | 15 +- src/plugins/Mys/types/GameLogin.d.ts | 8 +- src/types/BBS/Response.d.ts | 40 +++++- src/types/User/Account.d.ts | 8 +- src/utils/TGClient.ts | 10 +- src/web/request/TGRequest.ts | 5 +- src/web/request/getGameAccounts.ts | 6 +- src/web/request/getStoken.ts | 37 ++++- src/web/request/getTokens.ts | 6 +- 13 files changed, 336 insertions(+), 49 deletions(-) diff --git a/src-tauri/src/client.rs b/src-tauri/src/client.rs index 14cda1ae..082bc687 100644 --- a/src-tauri/src/client.rs +++ b/src-tauri/src/client.rs @@ -1,6 +1,6 @@ //! @file src/client.rs //! @desc 客户端模块,负责操作米游社客户端 -//! @since Beta v0.4.0 +//! @since Beta v0.4.3 use tauri::{ AppHandle, CustomMenuItem, LogicalSize, Manager, Menu, Size, Submenu, WindowBuilder, WindowUrl, @@ -22,11 +22,16 @@ fn create_utils_menu() -> Menu { } // 创建米游社客户端菜单 -fn create_mhy_menu() -> Menu { +fn create_mhy_menu(func: String) -> Menu { let top = CustomMenuItem::new("top".to_string(), "置顶"); let cancel_top = CustomMenuItem::new("cancel_top".to_string(), "取消置顶"); + let sign_in = CustomMenuItem::new("sign_in".to_string(), "用户登录"); let open_post = CustomMenuItem::new("open_post".to_string(), "打开帖子"); let utils_menu = Submenu::new("工具".to_string(), create_utils_menu()); + // 如果是登录 + if func == "config_sign_in" { + return Menu::new().add_item(sign_in); + } return Menu::new() .add_item(top) .add_item(cancel_top) @@ -75,7 +80,7 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { return; } WindowBuilder::from_config(&handle, mhy_window_config) - .menu(create_mhy_menu()) + .menu(create_mhy_menu(func)) .build() .expect("failed to create mhy_client") .on_menu_event(move |event| match event.menu_item_id() { @@ -164,6 +169,24 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { window.center().unwrap(); window.set_focus().unwrap(); } + "sign_in" => { + let window = handle.get_window("mhy_client").unwrap(); + let execute_js = r#"javascript:(async function(){ + // 首先检测是不是 user.mihoyo.com + const url = new URL(window.location.href); + if(url.hostname !== "user.mihoyo.com"){ + alert("当前页面不是米游社登录页面"); + return; + } + const ck = document.cookie; + const arg = { + method: 'teyvat_sign_in', + payload: ck, + } + await window.__TAURI__.event.emit('post_mhy_client',JSON.stringify(arg)); + })()"#; + window.eval(&execute_js).ok().unwrap(); + } _ => {} }); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 3dcf857f..c279fb0f 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -105,6 +105,11 @@ "windows": ["mhy_client"], "enableTauriAPI": true }, + { + "domain": "user.mihoyo.com", + "windows": ["mhy_client"], + "enableTauriAPI": true + }, { "domain": "webstatic.mihoyo.com", "windows": ["mhy_client"], diff --git a/src/components/config/tc-userBadge.vue b/src/components/config/tc-userBadge.vue index 70b2b84e..35cab289 100644 --- a/src/components/config/tc-userBadge.vue +++ b/src/components/config/tc-userBadge.vue @@ -10,17 +10,21 @@