mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-02 06:45:08 +08:00
🌱 初步构建米游社客户端子窗口
This commit is contained in:
35
src-tauri/src/client.rs
Normal file
35
src-tauri/src/client.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! @file src/client.rs
|
||||
//! @desc 客户端模块,负责操作米游社客户端
|
||||
//! @since Beta v0.3.3
|
||||
|
||||
use tauri::{AppHandle, Manager,WindowBuilder};
|
||||
|
||||
// 操作米游社客户端
|
||||
#[tauri::command]
|
||||
pub async fn operate_mhy(handle: AppHandle, arg: String) {
|
||||
let has_mhy_client = handle.get_window("mhy_client").is_some();
|
||||
let mhy_client;
|
||||
if has_mhy_client {
|
||||
mhy_client = handle.get_window("mhy_client").unwrap();
|
||||
} else {
|
||||
mhy_client = WindowBuilder::from_config(
|
||||
&handle,
|
||||
handle.config().tauri.windows.get(1).unwrap().clone()
|
||||
)
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
if mhy_client.is_visible().unwrap() == false {
|
||||
mhy_client.show().unwrap();
|
||||
}
|
||||
mhy_client.set_focus().unwrap();
|
||||
let js_code = r#"
|
||||
window.MiHoYoJSInterface = {
|
||||
postMessage: function(arg) { chrome.webview.postMessage(arg);console.log(arg) },
|
||||
closePage: function() { this.postMessage('{"method":"closePage"}') },
|
||||
};"#;
|
||||
mhy_client.eval(&js_code).ok().unwrap();
|
||||
let js_eval = format!("window.MiHoYoJSInterface.postMessage('{}')", arg);
|
||||
handle.emit_all("post_mhy_client", arg).unwrap();
|
||||
mhy_client.eval(&js_eval).ok().unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user