43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
mod events;
|
|
mod models;
|
|
mod server;
|
|
mod storage;
|
|
|
|
use std::io::{Read, Write};
|
|
use std::time::Duration;
|
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
pub fn run() {
|
|
// 在后台线程启动 HTTP 服务器
|
|
std::thread::spawn(|| {
|
|
let rt = tokio::runtime::Runtime::new().expect("无法创建 tokio runtime");
|
|
rt.block_on(async {
|
|
server::start().await;
|
|
});
|
|
});
|
|
|
|
// 等待 HTTP 服务器就绪后再打开窗口
|
|
for i in 0..50 {
|
|
if let Ok(mut s) = std::net::TcpStream::connect_timeout(
|
|
&"0.0.0.0:10801".parse().unwrap(),
|
|
Duration::from_millis(500),
|
|
) {
|
|
// 发送一个简单的 HTTP 请求测试
|
|
let _ = s.write_all(b"GET /api/state HTTP/1.0\r\n\r\n");
|
|
let mut buf = [0u8; 4];
|
|
if s.read(&mut buf).is_ok() {
|
|
break;
|
|
}
|
|
}
|
|
if i == 0 {
|
|
eprintln!("[dpm] 等待 HTTP 服务器启动...");
|
|
}
|
|
std::thread::sleep(Duration::from_millis(100));
|
|
}
|
|
|
|
tauri::Builder::default()
|
|
.plugin(tauri_plugin_opener::init())
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|