Native Window Management
Overview
src-tauri/…/window.rs contains the Rust/Tauri command surface for native window creation, lookup, and manipulation. Its only command is open_settings, which is registered with Tauri in src-tauri/…/main.rs via window::open_settings inside tauri::generate_handler!, making it callable from the frontend through Tauri's invoke system.
open_settings(app: AppHandle) uses the shared settings window label from src-tauri/…/constant.rs (WINDOW_SETTINGS, currently "settings") as the stable window identifier. It first calls app.get_webview_window(WINDOW_SETTINGS): if a settings webview already exists, the command calls window.show().unwrap() to make that existing native window visible. If no window exists for that label, it creates one with WebviewWindowBuilder::new(&app, WINDOW_SETTINGS, WebviewUrl::App("index.html".into())), builds it, and unwraps the result. The new settings window therefore loads the app's bundled index.html route rather than an external URL or a separate native view.
The module does not persist window state itself. The only state it reads is Tauri's runtime window registry via AppHandle::get_webview_window, and the only state it mutates is Tauri-managed native window visibility/creation. Failures from show() or build() are not propagated to callers; both are treated as fatal by unwrap().
Coupling
- If the settings window label changes in src-tauri/…/constant.rs, update any frontend code that looks up or invokes behavior for the
"settings"window as well as src-tauri/…/window.rs;open_settingsdepends on the label being the single identity used for lookup and creation, so a label mismatch creates duplicate or unreachable settings windows. - If the frontend settings UI moves away from the root app bundle route, update
WebviewUrl::App("index.html".into())in src-tauri/…/window.rs; the native command always opens that path when it creates the settings window. - If
open_settingsis renamed, moved, or its signature changes in src-tauri/…/window.rs, also update src-tauri/…/main.rs; Tauri only exposes the command because main.rs registerswindow::open_settingsingenerate_handler!.
Risks
- src-tauri/…/window.rs uses
unwrap()after bothwindow.show()andWebviewWindowBuilder::build(). If the existing window cannot be shown or the new webview cannot be built, the Tauri process panics instead of returning an error to the frontend.