From 1cb1033cbb07bea80dfa74ae23e86f0eb54e919f Mon Sep 17 00:00:00 2001 From: hauke Date: Fri, 6 Nov 2026 10:30:48 +0100 Subject: [PATCH] fix #14740: create windows after app state is managed Co-Authored-By: Claude Sonnet 5 --- src-tauri/src/lib.rs | 19 ++++++++++++++++++- src-tauri/tauri.conf.json | 9 ++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index b0b58f1..63faac0 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -7,7 +7,7 @@ mod tray; use recorder_core::pipeline; use recorder_core::secrets::KeyringSecrets; use recorder_core::store::Store; -use tauri::{Manager, WindowEvent}; +use tauri::{AppHandle, Manager, WebviewWindowBuilder, WindowEvent}; use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_log::{RotationStrategy, Target, TargetKind, TimezoneStrategy}; @@ -70,6 +70,12 @@ pub fn run() { // Before anything can start a run. processing::clear_upload_dir(app.handle()); app.manage(state); + // Windows are created here (`create: false` in tauri.conf.json) + // instead of by Tauri before `setup` runs: their webviews load + // immediately and invoke commands (list_calls, get_recording_state, + // get_pending_prompt) that need `AppState` to already be managed, + // which otherwise fails with "state not managed" right after start. + create_windows(app.handle())?; commands::apply_autostart(app.handle(), autostart); processing::delete_leftover_jobs(app.handle(), leftover_jobs); @@ -113,3 +119,14 @@ pub fn run() { .run(tauri::generate_context!()) .expect("error while building tauri application"); } + +/// Builds the windows declared in `tauri.conf.json` (there `"create": false`, +/// so Tauri does not build them itself before `setup` runs). Must run after +/// `app.manage(state)` and before anything that could show or use a window, +/// so no webview can invoke a command before `AppState` is managed. +fn create_windows(app: &AppHandle) -> tauri::Result<()> { + for config in app.config().app.windows.clone() { + WebviewWindowBuilder::from_config(app, &config)?.build()?; + } + Ok(()) +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 9b76b0e..b9cd8cc 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -18,7 +18,8 @@ "height": 680, "resizable": true, "fullscreen": false, - "visible": false + "visible": false, + "create": false }, { "label": "recorder", @@ -28,7 +29,8 @@ "height": 200, "alwaysOnTop": true, "resizable": false, - "visible": false + "visible": false, + "create": false }, { "label": "prompt", @@ -37,7 +39,8 @@ "width": 340, "height": 180, "alwaysOnTop": true, - "visible": false + "visible": false, + "create": false } ], "security": {