diff --git a/src-tauri/src/client.rs b/src-tauri/src/client.rs index d73ee686..fa5dba75 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.3.8 +//! @since Beta v0.3.9 use tauri::{AppHandle, CustomMenuItem, Manager, Menu, WindowBuilder, WindowUrl}; use url::Url; @@ -10,7 +10,8 @@ fn create_mhy_menu() -> Menu { let top = CustomMenuItem::new("top".to_string(), "置顶"); let cancel_top = CustomMenuItem::new("cancel_top".to_string(), "取消置顶"); let open_post = CustomMenuItem::new("open_post".to_string(), "打开帖子"); - return Menu::new().add_item(top).add_item(cancel_top).add_item(open_post); + let retry_bridge = CustomMenuItem::new("retry".to_string(), "重试"); + return Menu::new().add_item(top).add_item(cancel_top).add_item(open_post).add_item(retry_bridge); } // 获取米游社客户端入口地址 @@ -101,6 +102,16 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { })()"#; window.eval(&execute_js).ok().unwrap(); } + "retry" => { + let window = handle.get_window("mhy_client").unwrap(); + let execute_js = r#"javascript:(async function(){ + const arg = { + method: 'teyvat_retry', + } + await window.__TAURI__.event.emit('post_mhy_client',JSON.stringify(arg)); + })()"#; + window.eval(&execute_js).ok().unwrap(); + } _ => {} }); } diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index 6908b69d..fa622be2 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -279,6 +279,14 @@ class TGClient { case "teyvat_open": createPost(arg.payload); break; + case "teyvat_retry": { + const executeJS = `javascript:(function(){ + window.location.reload(); + })();`; + await invoke("execute_js", { label: "mhy_client", js: executeJS }); + await this.loadJSBridge(); + break; + } default: console.warn(`[customCallback] ${arg.method}`); }