pub struct App<R: Runtime = Wry> { /* private fields */ }Expand description
The instance of the currently running application.
This type implements Manager which allows for manipulation of global application items.
Implementations§
source§impl App<Wry>
impl App<Wry>
APIs specific to the wry runtime.
sourcepub fn wry_plugin<P: PluginBuilder<EventLoopMessage> + Send + 'static>(
&mut self,
plugin: P,
)
pub fn wry_plugin<P: PluginBuilder<EventLoopMessage> + Send + 'static>( &mut self, plugin: P, )
Adds a tauri_runtime_wry::Plugin using its tauri_runtime_wry::PluginBuilder.
§Stability
This API is unstable.
source§impl<R: Runtime> App<R>
impl<R: Runtime> App<R>
Registers a global menu event listener.
sourcepub fn on_tray_icon_event<F: Fn(&AppHandle<R>, TrayIconEvent) + Send + Sync + 'static>(
&self,
handler: F,
)
Available on desktop and crate feature tray-icon only.
pub fn on_tray_icon_event<F: Fn(&AppHandle<R>, TrayIconEvent) + Send + Sync + 'static>( &self, handler: F, )
desktop and crate feature tray-icon only.Registers a global tray icon menu event listener.
sourcepub fn tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
Available on desktop and crate feature tray-icon only.
pub fn tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
desktop and crate feature tray-icon only.Gets a tray icon using the provided id.
sourcepub fn remove_tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
Available on desktop and crate feature tray-icon only.
pub fn remove_tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
desktop and crate feature tray-icon only.Removes a tray icon using the provided id from tauri’s internal state and returns it.
Note that dropping the returned icon, may cause the tray icon to disappear if it wasn’t cloned somewhere else or referenced by JS.
sourcepub fn config(&self) -> &Config
pub fn config(&self) -> &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.
sourcepub fn primary_monitor(&self) -> Result<Option<Monitor>>
pub fn primary_monitor(&self) -> Result<Option<Monitor>>
Returns the primary monitor of the system.
Returns None if it can’t identify any monitor as a primary one.
sourcepub fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>
pub fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>
Returns the monitor that contains the given point.
sourcepub fn available_monitors(&self) -> Result<Vec<Monitor>>
pub fn available_monitors(&self) -> Result<Vec<Monitor>>
Returns the list of all the monitors available on the system.
sourcepub fn cursor_position(&self) -> Result<PhysicalPosition<f64>>
pub fn cursor_position(&self) -> Result<PhysicalPosition<f64>>
Get the cursor position relative to the top-left hand corner of the desktop.
Note that the top-left hand corner of the desktop is not necessarily the same as the screen. If the user uses a desktop with multiple monitors, the top-left hand corner of the desktop is the top-left hand corner of the main monitor on Windows and macOS or the top-left of the leftmost monitor on X11.
The coordinates can be negative if the top-left hand corner of the window is outside of the visible screen region.
sourcepub fn default_window_icon(&self) -> Option<&Image<'_>>
pub fn default_window_icon(&self) -> Option<&Image<'_>>
Returns the default window icon.
Returns the app-wide menu.
Sets the app-wide menu and returns the previous one.
If a window was not created with an explicit menu or had one set explicitly, this menu will be assigned to it.
Remove the app-wide menu and returns it.
If a window was not created with an explicit menu or had one set explicitly, this will remove the menu from it.
Hides the app-wide menu from windows that have it.
If a window was not created with an explicit menu or had one set explicitly, this will hide the menu from it.
Shows the app-wide menu for windows that have it.
If a window was not created with an explicit menu or had one set explicitly, this will show the menu for it.
sourcepub fn cleanup_before_exit(&self)
pub fn cleanup_before_exit(&self)
Runs necessary cleanup tasks before exiting the process. You should always exit the tauri app immediately after this function returns and not use any tauri-related APIs.
source§impl<R: Runtime> App<R>
impl<R: Runtime> App<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 set_device_event_filter(&mut self, filter: DeviceEventFilter)
pub fn set_device_event_filter(&mut self, filter: DeviceEventFilter)
Change the device event filter mode.
Since the DeviceEvent capture can lead to high CPU usage for unfocused windows, tao
will ignore them by default for unfocused windows on Windows. This method allows changing
the filter to explicitly capture them again.
§Platform-specific
- ** Linux / macOS / iOS / Android**: Unsupported.
§Examples
let mut app = tauri::Builder::default()
// on an actual app, remove the string argument
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("error while building tauri application");
app.set_device_event_filter(tauri::DeviceEventFilter::Always);
app.run(|_app_handle, _event| {});sourcepub fn run<F: FnMut(&AppHandle<R>, RunEvent) + 'static>(self, callback: F)
pub fn run<F: FnMut(&AppHandle<R>, RunEvent) + 'static>(self, callback: F)
Runs the application.
§Examples
let app = tauri::Builder::default()
// on an actual app, remove the string argument
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("error while building tauri application");
app.run(|_app_handle, event| match event {
tauri::RunEvent::ExitRequested { api, .. } => {
api.prevent_exit();
}
_ => {}
});sourcepub fn run_iteration<F: FnMut(&AppHandle<R>, RunEvent) + 'static>(
&mut self,
callback: F,
)
pub fn run_iteration<F: FnMut(&AppHandle<R>, RunEvent) + 'static>( &mut self, callback: F, )
Runs an iteration of the runtime event loop and immediately return.
Note that when using this API, app cleanup is not automatically done.
The cleanup calls App::cleanup_before_exit so you may want to call that function before exiting the application.
§Examples
use tauri::Manager;
let mut app = tauri::Builder::default()
// on an actual app, remove the string argument
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("error while building tauri application");
loop {
app.run_iteration(|_app, _event| {});
if app.webview_windows().is_empty() {
app.cleanup_before_exit();
break;
}
}Trait Implementations§
source§impl<R: Runtime> Emitter<R> for App<R>
impl<R: Runtime> Emitter<R> for App<R>
source§fn emit_to<I, S>(&self, target: I, event: &str, payload: S) -> Result<()>
fn emit_to<I, S>(&self, target: I, event: &str, payload: S) -> Result<()>
Emits an event to all targets matching the given target.
§Examples
use tauri::{Emitter, EventTarget};
#[tauri::command]
fn download(app: tauri::AppHandle) {
for i in 1..100 {
std::thread::sleep(std::time::Duration::from_millis(150));
// emit a download progress event to all listeners
app.emit_to(EventTarget::any(), "download-progress", i);
// emit an event to listeners that used App::listen or AppHandle::listen
app.emit_to(EventTarget::app(), "download-progress", i);
// emit an event to any webview/window/webviewWindow matching the given label
app.emit_to("updater", "download-progress", i); // similar to using EventTarget::labeled
app.emit_to(EventTarget::labeled("updater"), "download-progress", i);
// emit an event to listeners that used WebviewWindow::listen
app.emit_to(EventTarget::webview_window("updater"), "download-progress", i);
}
}source§fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>
fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>
Emits an event to all targets based on the given filter.
§Examples
use tauri::{Emitter, EventTarget};
#[tauri::command]
fn download(app: tauri::AppHandle) {
for i in 1..100 {
std::thread::sleep(std::time::Duration::from_millis(150));
// emit a download progress event to the updater window
app.emit_filter("download-progress", i, |t| match t {
EventTarget::WebviewWindow { label } => label == "main",
_ => false,
});
}
}source§impl<R: Runtime> HasDisplayHandle for App<R>
impl<R: Runtime> HasDisplayHandle for App<R>
source§fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
source§impl<R: Runtime> Listener<R> for App<R>
impl<R: Runtime> Listener<R> for App<R>
source§fn listen<F>(&self, event: impl Into<String>, handler: F) -> EventId
fn listen<F>(&self, event: impl Into<String>, handler: F) -> EventId
Listen to an event on this app.
§Examples
use tauri::Listener;
tauri::Builder::default()
.setup(|app| {
app.listen("component-loaded", move |event| {
println!("window just loaded a component");
});
Ok(())
});source§fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
Listen to an event on this app only once.
See Self::listen for more information.
source§fn unlisten(&self, id: EventId)
fn unlisten(&self, id: EventId)
Unlisten to an event on this app.
§Examples
use tauri::Listener;
tauri::Builder::default()
.setup(|app| {
let handler = app.listen("component-loaded", move |event| {
println!("app just loaded a component");
});
// stop listening to the event when you do not need it anymore
app.unlisten(handler);
Ok(())
});source§impl<R: Runtime> Manager<R> for App<R>
impl<R: Runtime> Manager<R> for App<R>
source§fn resources_table(&self) -> MutexGuard<'_, ResourceTable>
fn resources_table(&self) -> MutexGuard<'_, ResourceTable>
source§fn app_handle(&self) -> &AppHandle<R>
fn app_handle(&self) -> &AppHandle<R>
source§fn package_info(&self) -> &PackageInfo
fn package_info(&self) -> &PackageInfo
PackageInfo the manager was created with.source§fn get_window(&self, label: &str) -> Option<Window<R>>
fn get_window(&self, label: &str) -> Option<Window<R>>
unstable only.source§fn get_focused_window(&self) -> Option<Window<R>>
fn get_focused_window(&self) -> Option<Window<R>>
unstable only.None if there is not any focused window.source§fn windows(&self) -> HashMap<String, Window<R>>
fn windows(&self) -> HashMap<String, Window<R>>
unstable only.source§fn get_webview(&self, label: &str) -> Option<Webview<R>>
fn get_webview(&self, label: &str) -> Option<Webview<R>>
unstable only.source§fn webviews(&self) -> HashMap<String, Webview<R>>
fn webviews(&self) -> HashMap<String, Webview<R>>
unstable only.source§fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>>
fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>>
source§fn webview_windows(&self) -> HashMap<String, WebviewWindow<R>>
fn webview_windows(&self) -> HashMap<String, WebviewWindow<R>>
source§fn manage<T>(&self, state: T) -> bool
fn manage<T>(&self, state: T) -> bool
state to the state managed by the application. Read moresource§fn try_state<T>(&self) -> Option<State<'_, T>>
fn try_state<T>(&self) -> Option<State<'_, T>>
T. Read moresource§fn asset_protocol_scope(&self) -> Scope
fn asset_protocol_scope(&self) -> Scope
source§fn path(&self) -> &PathResolver<R>
fn path(&self) -> &PathResolver<R>
source§fn add_capability(&self, capability: impl RuntimeCapability) -> Result<()>
fn add_capability(&self, capability: impl RuntimeCapability) -> Result<()>
Auto Trait Implementations§
impl<R> Freeze for App<R>
impl<R = Wry<EventLoopMessage>> !RefUnwindSafe for App<R>
impl<R> Send for App<R>where
R: Send,
impl<R = Wry<EventLoopMessage>> !Sync for App<R>
impl<R> Unpin for App<R>
impl<R = Wry<EventLoopMessage>> !UnwindSafe for App<R>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
source§fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
HasDisplayHandle instead