Skip to content

Commit

Permalink
fix: on_event_message method signature for state management page (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
SauvageThomas committed Feb 10, 2025
1 parent cf0b304 commit c8f819b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/content/docs/develop/state-management.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@ Note that the return type must be [`Result`] if you use asynchronous commands.
Sometimes you may need to access the state outside of commands, such as in a different thread or in an event handler like `on_window_event`. In such cases, you can use the `state()` method of types that implement the [`Manager`] trait (such as the `AppHandle`) to get the state:

```rust
use tauri::{Builder, GlobalWindowEvent, Manager};
use tauri::{Builder, Window, WindowEvent, Manager};

#[derive(Default)]
struct AppState {
counter: u32,
}

// In an event handler:
fn on_window_event(event: GlobalWindowEvent) {
fn on_window_event(window: &Window, _event: &WindowEvent) {
// Get a handle to the app so we can get the global state.
let app_handle = event.window().app_handle();
let app_handle = window.app_handle();
let state = app_handle.state::<Mutex<AppState>>();

// Lock the mutex to mutably access the state.
Expand Down

0 comments on commit c8f819b

Please sign in to comment.