fix #14740: create windows after app state is managed
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+18
-1
@@ -7,7 +7,7 @@ mod tray;
|
|||||||
use recorder_core::pipeline;
|
use recorder_core::pipeline;
|
||||||
use recorder_core::secrets::KeyringSecrets;
|
use recorder_core::secrets::KeyringSecrets;
|
||||||
use recorder_core::store::Store;
|
use recorder_core::store::Store;
|
||||||
use tauri::{Manager, WindowEvent};
|
use tauri::{AppHandle, Manager, WebviewWindowBuilder, WindowEvent};
|
||||||
use tauri_plugin_autostart::MacosLauncher;
|
use tauri_plugin_autostart::MacosLauncher;
|
||||||
use tauri_plugin_log::{RotationStrategy, Target, TargetKind, TimezoneStrategy};
|
use tauri_plugin_log::{RotationStrategy, Target, TargetKind, TimezoneStrategy};
|
||||||
|
|
||||||
@@ -70,6 +70,12 @@ pub fn run() {
|
|||||||
// Before anything can start a run.
|
// Before anything can start a run.
|
||||||
processing::clear_upload_dir(app.handle());
|
processing::clear_upload_dir(app.handle());
|
||||||
app.manage(state);
|
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);
|
commands::apply_autostart(app.handle(), autostart);
|
||||||
processing::delete_leftover_jobs(app.handle(), leftover_jobs);
|
processing::delete_leftover_jobs(app.handle(), leftover_jobs);
|
||||||
|
|
||||||
@@ -113,3 +119,14 @@ pub fn run() {
|
|||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while building tauri application");
|
.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(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
"height": 680,
|
"height": 680,
|
||||||
"resizable": true,
|
"resizable": true,
|
||||||
"fullscreen": false,
|
"fullscreen": false,
|
||||||
"visible": false
|
"visible": false,
|
||||||
|
"create": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "recorder",
|
"label": "recorder",
|
||||||
@@ -28,7 +29,8 @@
|
|||||||
"height": 200,
|
"height": 200,
|
||||||
"alwaysOnTop": true,
|
"alwaysOnTop": true,
|
||||||
"resizable": false,
|
"resizable": false,
|
||||||
"visible": false
|
"visible": false,
|
||||||
|
"create": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "prompt",
|
"label": "prompt",
|
||||||
@@ -37,7 +39,8 @@
|
|||||||
"width": 340,
|
"width": 340,
|
||||||
"height": 180,
|
"height": 180,
|
||||||
"alwaysOnTop": true,
|
"alwaysOnTop": true,
|
||||||
"visible": false
|
"visible": false,
|
||||||
|
"create": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"security": {
|
"security": {
|
||||||
|
|||||||
Reference in New Issue
Block a user