"Inside a command, Tauri hands you what you need. Outside one — in setup, a thread, a timer — you carry an AppHandle to reach back into the app."
The Handle You Take With You
A command gets its State and Window injected, but plenty of code runs outside a command: the setup hook, a background thread, an async task, an OS event callback. In those places you hold an AppHandle — a cheap, clonable reference to the running application. Clone it, move it into a thread, and you can still emit events, read managed state, and find windows from anywhere.
The Manager Trait Is the Toolbox
Most of the useful methods — .state::<T>(), .emit(), .get_webview_window(), .path() for app directories — come from the Manager trait. App, AppHandle, Window, and WebviewWindow all implement it, so the same toolbox is available whether you're in setup with an &App or deep in a thread with an AppHandle. use tauri::Manager; is the import that lights those methods up.
Reaching State Without Injection
Inside a command you take State<T> as a parameter. Outside one, you fetch it from the handle: app.state::<T>() returns the same managed instance. This is how a background loop can read the same config a command reads, or how a setup hook can prime a cache. One managed value, two ways to reach it depending on where your code runs.