From 89804c83ac215f6dae637fd720209e0fec9455d4 Mon Sep 17 00:00:00 2001 From: Shenwei Wang Date: Tue, 17 Mar 2026 21:29:22 +0800 Subject: [PATCH] fix: use devUrl when dev (#556) --- src-tauri/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7162e5b..7ca3e04 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -21,8 +21,17 @@ pub fn run() { .plugin(tauri_plugin_localhost::Builder::new(port).build()) .plugin(tauri_plugin_window_state::Builder::default().build()) .setup(move |app| { - let url = format!("http://localhost:{}", port).parse().unwrap(); - let window_url = WebviewUrl::External(url); + // Dev: use devUrl from tauri.conf.json (http://localhost:8080) to support HMR + #[cfg(debug_assertions)] + let window_url = WebviewUrl::App(Default::default()); + + // Release: tauri-plugin-localhost serves bundled frontend assets on this port + #[cfg(not(debug_assertions))] + let window_url = { + let url = format!("http://localhost:{}", port).parse().unwrap(); + WebviewUrl::External(url) + }; + WebviewWindowBuilder::new(app, "main".to_string(), window_url) .title("Cinny") .build()?;