Struct tauri::App

source ·
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>

APIs specific to the wry runtime.

source

pub fn wry_plugin<P: PluginBuilder<EventLoopMessage> + '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>

source

pub fn updater(&self) -> UpdateBuilder<R>

Available on crate feature 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(())
  });
source

pub fn tray_handle(&self) -> SystemTrayHandle<R>

Available on crate feature 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(())
  });
source

pub fn tray_handle_by_id(&self, id: &str) -> Option<SystemTrayHandle<R>>

Available on crate feature 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(())
  });
source

pub fn path_resolver(&self) -> PathResolver

The path resolver for the application.

source

pub fn global_shortcut_manager(&self) -> R::GlobalShortcutManager

Available on crate feature global-shortcut only.

Gets a copy of the global shortcut manager instance.

source

pub fn config(&self) -> Arc<Config>

Gets the app’s configuration, defined on the tauri.conf.json file.

source

pub fn package_info(&self) -> &PackageInfo

Gets the app’s package information.

source

pub fn asset_resolver(&self) -> AssetResolver<R>

The application’s asset resolver.

source§

impl<R: Runtime> App<R>

source

pub fn handle(&self) -> AppHandle<R>

Gets a handle to the application instance.

source

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| {});
source

pub fn get_cli_matches(&self) -> Result<Matches>

Gets the argument matches of the CLI definition configured in tauri.conf.json.

§Examples
tauri::Builder::default()
  .setup(|app| {
    let matches = app.get_cli_matches()?;
    Ok(())
  });
source

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();
  }
  _ => {}
});
source

pub fn run_iteration(&mut self) -> RunIteration

Runs a iteration of the runtime event loop and immediately return.

Note that when using this API, app cleanup is not automatically done. The cleanup calls crate::api::process::kill_children so you may want to call that function before exiting the application. Additionally, the cleanup calls AppHandle#remove_system_tray (Windows only).

§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");
loop {
  let iteration = app.run_iteration();
  if iteration.window_count == 0 {
    break;
  }
}

Trait Implementations§

source§

impl<R: Debug + Runtime> Debug for App<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<R: Runtime> HasRawDisplayHandle for App<R>

source§

impl<R: Runtime> Manager<R> for App<R>

source§

fn app_handle(&self) -> AppHandle<R>

The application handle associated with this manager.
source§

fn config(&self) -> Arc<Config>

The Config the manager was created with.
source§

fn emit_all<S: Serialize + Clone>(&self, event: &str, payload: S) -> Result<()>

Emits an event to all windows. Read more
source§

fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>
where S: Serialize + Clone, F: Fn(&Window<R>) -> bool,

Emits an event to windows matching the filter critera. Read more
source§

fn emit_to<S: Serialize + Clone>( &self, label: &str, event: &str, payload: S ) -> Result<()>

Emits an event to the window with the specified label. Read more
source§

fn listen_global<F>(&self, event: impl Into<String>, handler: F) -> EventHandler
where F: Fn(Event) + Send + 'static,

Listen to a event triggered on any window (Window::trigger or Window::emit_and_trigger) or with Self::trigger_global. Read more
source§

fn once_global<F>(&self, event: impl Into<String>, handler: F) -> EventHandler
where F: FnOnce(Event) + Send + 'static,

Listen to a global event only once. Read more
source§

fn trigger_global(&self, event: &str, data: Option<String>)

Trigger a global event to Rust listeners. To send the events to the webview, see 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 more
source§

fn unlisten(&self, handler_id: EventHandler)

Remove an event listener. Read more
source§

fn get_window(&self, label: &str) -> Option<Window<R>>

Fetch a single window from the manager.
source§

fn get_focused_window(&self) -> Option<Window<R>>

Fetch the focused window. Returns None if there is not any focused window.
source§

fn windows(&self) -> HashMap<String, Window<R>>

Fetch all managed windows.
source§

fn manage<T>(&self, state: T) -> bool
where T: Send + Sync + 'static,

Add state to the state managed by the application. Read more
source§

fn state<T>(&self) -> State<'_, T>
where T: Send + Sync + 'static,

Retrieves the managed state for the type T. Read more
source§

fn try_state<T>(&self) -> Option<State<'_, T>>
where T: Send + Sync + 'static,

Attempts to retrieve the managed state for the type T. Read more
source§

fn env(&self) -> Env

Gets the managed Env.
source§

fn fs_scope(&self) -> FsScope

Gets the scope for the filesystem APIs.
source§

fn ipc_scope(&self) -> IpcScope

Gets the scope for the IPC.
source§

fn asset_protocol_scope(&self) -> FsScope

Gets the scope for the asset protocol.
source§

fn shell_scope(&self) -> ShellScope

Gets the scope for the shell execute APIs.

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> Sync for App<R>
where R: Sync,

§

impl<R> Unpin for App<R>

§

impl<R = Wry<EventLoopMessage>> !UnwindSafe for App<R>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more