更新 Tauri 配置,调整开发命令和 URL,增强应用启动逻辑

This commit is contained in:
2025-12-23 13:04:27 +08:00
parent f6b2c74d2d
commit 798df0dedd
3 changed files with 20 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
use tauri::{Manager, Url};
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
@@ -6,8 +8,22 @@ fn greet(name: &str) -> String {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
// 从命令行参数获取 URL
let args: Vec<String> = std::env::args().collect();
let url = args.get(1).cloned();
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.setup(move |app| {
if let Some(url_str) = url {
if let Ok(parsed_url) = Url::parse(&url_str) {
if let Some(window) = app.webview_windows().get("main") {
let _ = window.navigate(parsed_url);
}
}
}
Ok(())
})
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View File

@@ -4,8 +4,8 @@
"version": "0.1.0",
"identifier": "com.xiong.tauri-template",
"build": {
"beforeDevCommand": "bun run dev",
"devUrl": "http://localhost:1420",
"beforeDevCommand": "",
"devUrl": "http://localhost:51515/root/light-code-center/",
"beforeBuildCommand": "bun run build",
"frontendDist": "../dist"
},