diff --git a/src-tauri/src/client/menu.rs b/src-tauri/src/client/menu.rs index 745a5af9..54a5507e 100644 --- a/src-tauri/src/client/menu.rs +++ b/src-tauri/src/client/menu.rs @@ -1,6 +1,6 @@ //! @file src/client/menu.rs //! @desc 客户端菜单模块,负责操作米游社客户端菜单 -//! @since Beta v0.4.3 +//! @since Beta v0.4.5 use tauri::{AppHandle, CustomMenuItem, LogicalSize, Manager, Menu, Size, Submenu, WindowUrl}; use url::Url; @@ -27,8 +27,8 @@ fn create_utils_menu() -> Menu { let retry_bridge = CustomMenuItem::new("retry".to_string(), "重试桥接"); let mock_touch = CustomMenuItem::new("mock_touch".to_string(), "模拟触摸"); let remove_overlay = CustomMenuItem::new("remove_overlay".to_string(), "移除遮罩"); - // 旋转窗口/切换横屏或者竖屏 let rotate_window = CustomMenuItem::new("rotate_window".to_string(), "旋转窗口"); + let switch_ua = CustomMenuItem::new("switch_ua".to_string(), "切换 UA"); return Menu::new() .add_item(retry_bridge) .add_item(mock_touch) @@ -65,6 +65,7 @@ pub fn handle_menu_event(app_handle: AppHandle, event: tauri::MenuEvent) { "mock_touch" => handle_menu_mock_touch(app_handle), "remove_overlay" => handle_menu_remove_overlay(app_handle), "rotate_window" => handle_menu_rotate_window(app_handle), + "switch_ua" => handle_menu_switch_ua(app_handle), _ => {} } } @@ -210,3 +211,23 @@ fn handle_menu_rotate_window(app_handle: AppHandle) { window.center().unwrap(); window.set_focus().unwrap(); } + +// 处理切换 UA 菜单 +fn handle_menu_switch_ua(app_handle: AppHandle) { + let window = app_handle.get_window("mhy_client"); + let execute_js = r#" + javascript:(async function(){ + const isPc = navigator.userAgent.includes("Windows NT"); + const arg = { + method: 'teyvat_switch_ua', + payload: { + url: window.location.href, + isPc, + } + } + await window.__TAURI__.event.emit('post_mhy_client',JSON.stringify(arg)); + })()"#; + if window.is_some() { + window.unwrap().eval(&execute_js).ok().unwrap(); + } +} diff --git a/src-tauri/src/client/mod.rs b/src-tauri/src/client/mod.rs index 128a4e34..0a396a5d 100644 --- a/src-tauri/src/client/mod.rs +++ b/src-tauri/src/client/mod.rs @@ -1,6 +1,6 @@ //! @file src/client/mod.rs //! @desc 客户端模块,负责操作米游社客户端 -//! @since Beta v0.4.3 +//! @since Beta v0.4.5 mod menu; use tauri::async_runtime::block_on; @@ -15,6 +15,11 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { } else { mhy_window_config.url = menu::get_mhy_client_url(func.clone()); } + // if pc { + // let user_agent = mhy_window_config.user_agent.as_ref().unwrap(); + // let version = user_agent.split("/").last().unwrap(); + // mhy_window_config.user_agent = Some(format!("Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/{}", version)); + // } if func == "birthday" || func == "web_act" || url.starts_with("https://webstatic.mihoyo.com/ys/event/e20220303-birthday/index.html") diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index 0b1d6ef7..bcf0c24b 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -200,11 +200,6 @@ daily_note - - -