diff --git a/src-tauri/src/client.rs b/src-tauri/src/client.rs index 608d3a31..934b825e 100644 --- a/src-tauri/src/client.rs +++ b/src-tauri/src/client.rs @@ -2,45 +2,37 @@ //! @desc 客户端模块,负责操作米游社客户端 //! @since Beta v0.3.3 -use tauri::{AppHandle, Manager,WindowBuilder, WindowUrl}; +use tauri::{AppHandle, Manager, WindowBuilder, WindowUrl}; use url::Url; // 获取米游社客户端入口地址 fn get_mhy_client_url(func: String) -> WindowUrl { - let mut url_res: Url = "https://bbs.mihoyo.com/ys/".parse().unwrap(); - if func == "sign_in" { - url_res = "https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501".parse().unwrap(); - } else if func == "game_record" { - url_res = "https://webstatic.mihoyo.com/app/community-game-records/index.html".parse().unwrap(); - } - return WindowUrl::External(url_res); + let mut url_res: Url = "https://bbs.mihoyo.com/ys/".parse().unwrap(); + if func == "sign_in" { + url_res = "https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501" + .parse() + .unwrap(); + } else if func == "game_record" { + url_res = "https://webstatic.mihoyo.com/app/community-game-records/index.html".parse().unwrap(); + } + return WindowUrl::External(url_res); } // 操作米游社客户端 #[tauri::command] -pub async fn create_mhy_client(handle: AppHandle, func: String, arg: String) { - dbg!(&arg); - let has_mhy_client = handle.get_window("mhy_client").is_some(); - let mut mhy_client_config = handle.config().tauri.windows.get(1).unwrap().clone(); - mhy_client_config.url = get_mhy_client_url(func.clone()); - let mhy_client; - if has_mhy_client { - mhy_client = handle.get_window("mhy_client").unwrap(); - mhy_client.close().unwrap(); - } else { - mhy_client = WindowBuilder::from_config( - &handle, - mhy_client_config, - ) - .build() - .unwrap(); - mhy_client.show().unwrap(); - mhy_client.set_focus().unwrap(); - let js_code = r#" - window.MiHoYoJSInterface = { - postMessage: function(arg) { window.__TAURI__.event.emit('post_mhy_client', arg) }, - closePage: function() { this.postMessage('{"method":"closePage"}') }, - };"#; - mhy_client.eval(&js_code).ok().unwrap(); - } -} \ No newline at end of file +pub async fn create_mhy_client(handle: AppHandle, func: String) { + let mut mhy_window_config = handle.config().tauri.windows.get(1).unwrap().clone(); + mhy_window_config.url = get_mhy_client_url(func.clone()); + let has_mhy_client = handle.get_window("mhy_client").is_some(); + if has_mhy_client { + return; + } + let js_bridge = r#" + window.MiHoYoJSInterface = { + postMessage: function(arg) { window.__TAURI__.event.emit('post_mhy_client', arg) }, + closePage: function() { this.postMessage('{"method":"closePage"}') }, + }; + "#; + let mhy_client = WindowBuilder::from_config(&handle, mhy_window_config).build(); + mhy_client.unwrap().eval(&js_bridge).ok().unwrap(); +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e592211e..57978985 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,3 +1,7 @@ +//! @file src/main.rs +//! @desc 主模块,用于启动应用 +//! @since Beta v0.3.3 + // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] @@ -10,68 +14,77 @@ static mut DEEP_LINK_REGISTERED: bool = false; #[tauri::command] async fn init_app(app_handle: tauri::AppHandle) { - dbg!("init_app"); - unsafe { - if APP_INITIALIZED == true && DEEP_LINK_REGISTERED == true { - return; - } - } - app_handle.emit_all("initApp", ()).unwrap(); - unsafe { - APP_INITIALIZED = true; + dbg!("init_app"); + unsafe { + if APP_INITIALIZED == true && DEEP_LINK_REGISTERED == true { + return; } + } + app_handle.emit_all("initApp", ()).unwrap(); + unsafe { + APP_INITIALIZED = true; + } } #[tauri::command] async fn register_deep_link(app_handle: tauri::AppHandle) { - dbg!("register_deep_link"); - unsafe { - if DEEP_LINK_REGISTERED == true { - return; - } - } - tauri_plugin_deep_link::register( - "teyvatguide", - move |request| { - dbg!(&request); - app_handle.emit_all("active_deep_link", request).unwrap(); - }, - ) - .unwrap(); - unsafe { - DEEP_LINK_REGISTERED = true; + dbg!("register_deep_link"); + unsafe { + if DEEP_LINK_REGISTERED == true { + return; } + } + tauri_plugin_deep_link::register("teyvatguide", move |request| { + dbg!(&request); + app_handle.emit_all("active_deep_link", request).unwrap(); + }) + .unwrap(); + unsafe { + DEEP_LINK_REGISTERED = true; + } +} + +// 执行 js +#[tauri::command] +async fn execute_js(app_handle: tauri::AppHandle, label: String, js: String) { + let window = app_handle.get_window(&label).unwrap(); + window.eval(&js).ok().unwrap(); } fn main() { - tauri_plugin_deep_link::prepare("teyvatguide"); - tauri::Builder::default() - .on_window_event(|event| { - match event.event() { - tauri::WindowEvent::CloseRequested { api, .. } => { - api.prevent_close(); - let window = event.window().clone(); - if window.label() == "TeyvatGuide" { - // 子窗口 label 的数组 - const SUB_WINDOW_LABELS: [&str; 3] = ["Sub_window", "Dev_JSON", "mhy_client"]; - for label in SUB_WINDOW_LABELS.iter() { - let sub = window.get_window(label).unwrap(); - sub.close().unwrap(); - } - } - window.close().unwrap(); - }, - _ => {} + tauri_plugin_deep_link::prepare("teyvatguide"); + tauri::Builder::default() + .on_window_event(|event| { + match event.event() { + tauri::WindowEvent::CloseRequested { api, .. } => { + api.prevent_close(); + let window = event.window().clone(); + if window.label() == "TeyvatGuide" { + // 子窗口 label 的数组 + const SUB_WINDOW_LABELS: [&str; 3] = ["Sub_window", "Dev_JSON", "mhy_client"]; + for label in SUB_WINDOW_LABELS.iter() { + let sub = window.get_window(label).unwrap(); + sub.close().unwrap(); } - }) - .plugin(tauri_plugin_sql::Builder::default().build()) - .invoke_handler(tauri::generate_handler![register_deep_link, init_app, client::create_mhy_client]) - .setup(|_app| { - let _window = _app.get_window("TeyvatGuide").unwrap(); - #[cfg(debug_assertions)] // only include this code on debug builds - _window.open_devtools(); // open the devtools on startup - Ok(()) - }) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); + } + window.close().unwrap(); + } + _ => {} + } + }) + .plugin(tauri_plugin_sql::Builder::default().build()) + .invoke_handler(tauri::generate_handler![ + register_deep_link, + init_app, + execute_js, + client::create_mhy_client, + ]) + .setup(|_app| { + let _window = _app.get_window("TeyvatGuide").unwrap(); + #[cfg(debug_assertions)] // only include this code on debug builds + _window.open_devtools(); // open the devtools on startup + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); } diff --git a/src/components/hutaoAbyss/hta-tab-team.vue b/src/components/hutaoAbyss/hta-tab-team.vue index 2e19515a..f53c4f04 100644 --- a/src/components/hutaoAbyss/hta-tab-team.vue +++ b/src/components/hutaoAbyss/hta-tab-team.vue @@ -104,14 +104,13 @@ onMounted(async () => { .hta-tuf-box { display: flex; + overflow: hidden auto; width: 100%; max-height: 100%; flex-direction: column; align-items: center; justify-content: center; border-radius: 5px; - overflow-x: hidden; - overflow-y: auto; row-gap: 10px; } diff --git a/src/pages/common/Test.vue b/src/pages/common/Test.vue index 13db1194..e514684b 100644 --- a/src/pages/common/Test.vue +++ b/src/pages/common/Test.vue @@ -41,7 +41,7 @@ async function getGC(): Promise { } async function tryNewWindow(): Promise { - await mhyClient.open("game_record", "test"); + await mhyClient.open("game_record"); }