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 @@
+