pub struct AppHandle<R: Runtime = Wry> { /* private fields */ }
Expand description
A handle to the currently running application.
This type implements Manager
which allows for manipulation of global application items.
Implementations§
source§impl AppHandle<Wry>
impl AppHandle<Wry>
APIs specific to the wry runtime.
sourcepub fn create_tao_window<F: FnOnce() -> (String, WryWindowBuilder) + Send + 'static>(
&self,
f: F
) -> Result<Weak<Window>>
pub fn create_tao_window<F: FnOnce() -> (String, WryWindowBuilder) + Send + 'static>( &self, f: F ) -> Result<Weak<Window>>
Create a new tao window using a callback. The event loop must be running at this point.
sourcepub fn send_tao_window_event(
&self,
window_id: WindowId,
message: WindowMessage
) -> Result<()>
pub fn send_tao_window_event( &self, window_id: WindowId, message: WindowMessage ) -> Result<()>
Sends a window message to the event loop.
source§impl<R: Runtime> AppHandle<R>
impl<R: Runtime> AppHandle<R>
sourcepub fn run_on_main_thread<F: FnOnce() + Send + 'static>(
&self,
f: F
) -> Result<()>
pub fn run_on_main_thread<F: FnOnce() + Send + 'static>( &self, f: F ) -> Result<()>
Runs the given closure on the main thread.
sourcepub fn plugin<P: Plugin<R> + 'static>(&self, plugin: P) -> Result<()>
pub fn plugin<P: Plugin<R> + 'static>(&self, plugin: P) -> Result<()>
Adds a Tauri application plugin.
This function can be used to register a plugin that is loaded dynamically e.g. after login.
For plugins that are created when the app is started, prefer Builder::plugin
.
See Builder::plugin
for more information.
Examples
use tauri::{plugin::{Builder as PluginBuilder, TauriPlugin}, Runtime};
fn init_plugin<R: Runtime>() -> TauriPlugin<R> {
PluginBuilder::new("dummy").build()
}
tauri::Builder::default()
.setup(move |app| {
let handle = app.handle();
std::thread::spawn(move || {
handle.plugin(init_plugin());
});
Ok(())
});
sourcepub fn remove_plugin(&self, plugin: &'static str) -> bool
pub fn remove_plugin(&self, plugin: &'static str) -> bool
Removes the plugin with the given name.
Examples
use tauri::{plugin::{Builder as PluginBuilder, TauriPlugin, Plugin}, Runtime};
fn init_plugin<R: Runtime>() -> TauriPlugin<R> {
PluginBuilder::new("dummy").build()
}
let plugin = init_plugin();
// `.name()` requires the `PLugin` trait import
let plugin_name = plugin.name();
tauri::Builder::default()
.plugin(plugin)
.setup(move |app| {
let handle = app.handle();
std::thread::spawn(move || {
handle.remove_plugin(plugin_name);
});
Ok(())
});
sourcepub fn exit(&self, exit_code: i32)
pub fn exit(&self, exit_code: i32)
Exits the app. This is the same as std::process::exit
, but it performs cleanup on this application.
sourcepub fn restart(&self)
pub fn restart(&self)
Restarts the app. This is the same as crate::api::process::restart
, but it performs cleanup on this application.
source§impl<R: Runtime> AppHandle<R>
impl<R: Runtime> AppHandle<R>
sourcepub fn updater(&self) -> UpdateBuilder<R>
Available on crate feature updater
only.
pub fn updater(&self) -> UpdateBuilder<R>
updater
only.Gets the updater builder to manually check if an update is available.
Examples
tauri::Builder::default()
.setup(|app| {
let handle = app.handle();
tauri::async_runtime::spawn(async move {
let response = handle.updater().check().await;
});
Ok(())
});
sourcepub fn tray_handle(&self) -> SystemTrayHandle<R>
Available on crate feature system-tray
only.
pub fn tray_handle(&self) -> SystemTrayHandle<R>
system-tray
only.Gets a handle to the first system tray.
Prefer Self::tray_handle_by_id
when multiple system trays are created.
Examples
use tauri::{CustomMenuItem, SystemTray, SystemTrayMenu};
tauri::Builder::default()
.setup(|app| {
let app_handle = app.handle();
SystemTray::new()
.with_menu(
SystemTrayMenu::new()
.add_item(CustomMenuItem::new("quit", "Quit"))
.add_item(CustomMenuItem::new("open", "Open"))
)
.on_event(move |event| {
let tray_handle = app_handle.tray_handle();
})
.build(app)?;
Ok(())
});
sourcepub fn tray_handle_by_id(&self, id: &str) -> Option<SystemTrayHandle<R>>
Available on crate feature system-tray
only.
pub fn tray_handle_by_id(&self, id: &str) -> Option<SystemTrayHandle<R>>
system-tray
only.Gets a handle to a system tray by its id.
use tauri::{CustomMenuItem, SystemTray, SystemTrayMenu};
tauri::Builder::default()
.setup(|app| {
let app_handle = app.handle();
let tray_id = "my-tray";
SystemTray::new()
.with_id(tray_id)
.with_menu(
SystemTrayMenu::new()
.add_item(CustomMenuItem::new("quit", "Quit"))
.add_item(CustomMenuItem::new("open", "Open"))
)
.on_event(move |event| {
let tray_handle = app_handle.tray_handle_by_id(tray_id).unwrap();
})
.build(app)?;
Ok(())
});
sourcepub fn path_resolver(&self) -> PathResolver
pub fn path_resolver(&self) -> PathResolver
The path resolver for the application.
sourcepub fn global_shortcut_manager(&self) -> R::GlobalShortcutManager
Available on crate feature global-shortcut
only.
pub fn global_shortcut_manager(&self) -> R::GlobalShortcutManager
global-shortcut
only.Gets a copy of the global shortcut manager instance.
sourcepub fn clipboard_manager(&self) -> R::ClipboardManager
Available on crate feature clipboard
only.
pub fn clipboard_manager(&self) -> R::ClipboardManager
clipboard
only.Gets a copy of the clipboard manager instance.
sourcepub fn config(&self) -> Arc<Config>
pub fn config(&self) -> Arc<Config>
Gets the app’s configuration, defined on the tauri.conf.json
file.
sourcepub fn package_info(&self) -> &PackageInfo
pub fn package_info(&self) -> &PackageInfo
Gets the app’s package information.
sourcepub fn asset_resolver(&self) -> AssetResolver<R>
pub fn asset_resolver(&self) -> AssetResolver<R>
The application’s asset resolver.
Trait Implementations§
source§impl<'de, R: Runtime> CommandArg<'de, R> for AppHandle<R>
impl<'de, R: Runtime> CommandArg<'de, R> for AppHandle<R>
source§fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
Grabs the Window
from the CommandItem
and returns the associated AppHandle
. This will never fail.
source§impl<R: Debug + Runtime> Debug for AppHandle<R>where
R::Handle: Debug,
R::GlobalShortcutManager: Debug,
R::ClipboardManager: Debug,
impl<R: Debug + Runtime> Debug for AppHandle<R>where R::Handle: Debug, R::GlobalShortcutManager: Debug, R::ClipboardManager: Debug,
source§impl<R: Runtime> HasRawDisplayHandle for AppHandle<R>
impl<R: Runtime> HasRawDisplayHandle for AppHandle<R>
fn raw_display_handle(&self) -> RawDisplayHandle
source§impl<R: Runtime> Manager<R> for AppHandle<R>
impl<R: Runtime> Manager<R> for AppHandle<R>
source§fn app_handle(&self) -> AppHandle<R>
fn app_handle(&self) -> AppHandle<R>
source§fn emit_all<S: Serialize + Clone>(&self, event: &str, payload: S) -> Result<()>
fn emit_all<S: Serialize + Clone>(&self, event: &str, payload: S) -> Result<()>
source§fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>where
S: Serialize + Clone,
F: Fn(&Window<R>) -> bool,
fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>where S: Serialize + Clone, F: Fn(&Window<R>) -> bool,
source§fn emit_to<S: Serialize + Clone>(
&self,
label: &str,
event: &str,
payload: S
) -> Result<()>
fn emit_to<S: Serialize + Clone>( &self, label: &str, event: &str, payload: S ) -> Result<()>
source§fn listen_global<F>(&self, event: impl Into<String>, handler: F) -> EventHandlerwhere
F: Fn(Event) + Send + 'static,
fn listen_global<F>(&self, event: impl Into<String>, handler: F) -> EventHandlerwhere F: Fn(Event) + Send + 'static,
Window::trigger
or Window::emit_and_trigger
) or with Self::trigger_global
. Read moresource§fn once_global<F>(&self, event: impl Into<String>, handler: F) -> EventHandlerwhere
F: FnOnce(Event) + Send + 'static,
fn once_global<F>(&self, event: impl Into<String>, handler: F) -> EventHandlerwhere F: FnOnce(Event) + Send + 'static,
source§fn trigger_global(&self, event: &str, data: Option<String>)
fn trigger_global(&self, event: &str, data: Option<String>)
Self::emit_all
and Self::emit_to
.
To trigger listeners registed on an specific window, see Window::trigger
.
To trigger all listeners, see Window::emit_and_trigger
. Read moresource§fn unlisten(&self, handler_id: EventHandler)
fn unlisten(&self, handler_id: EventHandler)
source§fn get_window(&self, label: &str) -> Option<Window<R>>
fn get_window(&self, label: &str) -> Option<Window<R>>
source§fn get_focused_window(&self) -> Option<Window<R>>
fn get_focused_window(&self) -> Option<Window<R>>
None
if there is not any focused window.source§fn manage<T>(&self, state: T) -> boolwhere
T: Send + Sync + 'static,
fn manage<T>(&self, state: T) -> boolwhere T: Send + Sync + 'static,
state
to the state managed by the application. Read moresource§fn state<T>(&self) -> State<'_, T>where
T: Send + Sync + 'static,
fn state<T>(&self) -> State<'_, T>where T: Send + Sync + 'static,
T
. Read moresource§fn try_state<T>(&self) -> Option<State<'_, T>>where
T: Send + Sync + 'static,
fn try_state<T>(&self) -> Option<State<'_, T>>where T: Send + Sync + 'static,
T
. Read more