🔥 部分跳转改为新建窗口

This commit is contained in:
目棃
2024-04-03 14:06:34 +08:00
parent 4985bcde29
commit 5aba7bcecc
6 changed files with 34 additions and 16 deletions

View File

@@ -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();
}
}

View File

@@ -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")