Skip to content

Commit ca3b514

Browse files
authored
fix: panic caused by "state() called before manage()" (#806)
This commit fixes the following panic: ``` Time: [2025-07-23-17-03-23] Location: [/Users/steve/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tauri-2.5.1/src/lib.rs:742:7] Message: [state() called before manage() for tauri_plugin_global_shortcut::GlobalShortcut<tauri_runtime_wry::Wry<tauri::EventLoopMessage>>] ``` The root cause is that, in a Tauri application, before you can access a piece of managed state with the .state() method, you must first register it with Tauri using .manage(). When a user reigsters hotkey for an extension, initializing extensions will invoke the .state() method, at that point, .manage() hasn't been called. The fix is simple, we simply call .manage() earlies (invoked by our `shortcut::enable_shortcut(app)` function).
1 parent c694c4e commit ca3b514

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Information about release notes of Coco Server is provided here.
3535
- fix: enter key problem #794
3636
- fix: fix selection issue after renaming #800
3737
- fix: fix shortcut issue in windows context menu #804
38+
- fix: panic caused by "state() called before manage()" #806
3839

3940
### ✈️ Improvements
4041

src-tauri/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ pub fn run() {
196196
app.manage(registry); // Store registry in Tauri's app state
197197
app.manage(server::websocket::WebSocketManager::default());
198198

199+
// This has to be called before initializing extensions as doing that
200+
// requires access to the shortcut store, which will be set by this
201+
// function.
202+
shortcut::enable_shortcut(app);
203+
199204
block_on(async {
200205
init(app.handle()).await;
201206

@@ -216,8 +221,6 @@ pub fn run() {
216221
}
217222
});
218223

219-
shortcut::enable_shortcut(app);
220-
221224
ensure_autostart_state_consistent(app)?;
222225

223226
// app.listen("theme-changed", move |event| {

0 commit comments

Comments
 (0)