Struct tauri::Builder
pub struct Builder<R: Runtime> { /* fields omitted */ }
Expand description
Builds a Tauri application.
#
ImplementationsRuntime> Builder<R>[src]#
impl<R:new() -> Self[src]#
pub fnCreates a new App builder.
invoke_handler<F>(self, invoke_handler: F) -> Self where F: Fn(Invoke<R>) + Send + Sync + 'static,[src]#
pub fnDefines the JS message handler callback.
setup<F>(self, setup: F) -> Self where F: Fn(&mut App<R>) -> Result<(), Box<dyn Error + Send>> + Send + 'static,[src]#
pub fnDefines the setup hook.
on_page_load<F>(self, on_page_load: F) -> Self where F: Fn(Window<R>, PageLoadPayload) + Send + Sync + 'static,[src]#
pub fnDefines the page load hook.
plugin<P: Plugin<R> + 'static>(self, plugin: P) -> Self[src]#
pub fnAdds a plugin to the runtime.
manage<T>(self, state: T) -> Self where T: Send + Sync + 'static,[src]#
pub fnAdd state
to the state managed by the application.
This method can be called any number of times as long as each call refers to a different T
.
Managed state can be retrieved by any request handler via the State
request guard. In particular, if a value of type T
is managed by Tauri, adding State<T>
to the list of arguments in a request handler instructs Tauri to retrieve the managed value.
#
PanicsPanics if state of type T
is already being managed.
#
MutabilitySince the managed state is global and must be Send
+ Sync
, mutations can only happen through interior mutability:
ⓘ
use std::{collections::HashMap, sync::Mutex};
use tauri::State;
// here we use Mutex to achieve interior mutability
struct Storage(Mutex<HashMap<u64, String>>);
struct Connection;
struct DbConnection(Mutex<Option<Connection>>);
#[tauri::command]
fn connect(connection: State<DbConnection>) {
// initialize the connection, mutating the state with interior mutability
*connection.0.lock().unwrap() = Some(Connection {});
}
#[tauri::command]
fn storage_insert(key: u64, value: String, storage: State<Storage>) {
// mutate the storage behind the Mutex
storage.0.lock().unwrap().insert(key, value);
}
fn main() {
Builder::default()
.manage(Storage(Default::default()))
.manage(DbConnection(Default::default()))
.invoke_handler(tauri::generate_handler![connect, storage_insert])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#
Exampleⓘ
use tauri::State;
struct MyInt(isize);
struct MyString(String);
#[tauri::command]
fn int_command(state: State<MyInt>) -> String {
format!("The stateful int is: {}", state.0)
}
#[tauri::command]
fn string_command<'r>(state: State<'r, MyString>) {
println!("state: {}", state.inner().0);
}
fn main() {
tauri::Builder::default()
.manage(MyInt(10))
.manage(MyString("Hello, managed state!".to_string()))
.invoke_handler(tauri::generate_handler![int_command, string_command])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
create_window<F>( self, label: impl Into<String>, url: WindowUrl, setup: F ) -> Self where F: FnOnce(<R::Dispatcher as Dispatch>::WindowBuilder, WebviewAttributes) -> (<R::Dispatcher as Dispatch>::WindowBuilder, WebviewAttributes),[src]#
pub fnCreates a new webview window.
menu(self, menu: Menu) -> Self[src]#
pub fnSets the menu to use on all windows.
on_menu_event<F: Fn(WindowMenuEvent<R>) + Send + Sync + 'static>( self, handler: F ) -> Self[src]#
pub fnRegisters a menu event handler for all windows.
on_window_event<F: Fn(GlobalWindowEvent<R>) + Send + Sync + 'static>( self, handler: F ) -> Self[src]#
pub fnRegisters a window event handler for all windows.
register_uri_scheme_protocol<N: Into<String>, H: Fn(&AppHandle<R>, &HttpRequest) -> Result<HttpResponse, Box<dyn Error>> + Send + Sync + 'static>( self, uri_scheme: N, protocol: H ) -> Self[src]#
pub fnRegisters a URI scheme protocol available to all webviews. Leverages setURLSchemeHandler on macOS, AddWebResourceRequestedFilter on Windows and webkit-web-context-register-uri-scheme on Linux.
#
Argumentsuri_scheme
The URI scheme to register, such asexample
.protocol
the protocol associated with the given URI scheme. It’s a function that takes an URL such asexample://localhost/asset.css
.
build<A: Assets>(self, context: Context<A>) -> Result<App<R>>[src]#
pub fnBuilds the application.
run<A: Assets>(self, context: Context<A>) -> Result<()>[src]#
pub fnRuns the configured Tauri application.
#
Trait ImplementationsDefault for Builder<Wry>[src]#
implMake Wry
the default Runtime
for Builder
default() -> Self[src]#
fnReturns the “default value” for a type. Read more
#
Auto Trait ImplementationsRefUnwindSafe for Builder<R>#
impl<R> \!Send for Builder<R> where <<R as Runtime>::Dispatcher as Dispatch>::WindowBuilder: Send,#
impl<R>Sync for Builder<R>#
impl<R> \!Unpin for Builder<R> where <<R as Runtime>::Dispatcher as Dispatch>::WindowBuilder: Unpin,#
impl<R>UnwindSafe for Builder<R>#
impl<R> \!#
Blanket ImplementationsAny for T where T: 'static + ?Sized,[src]#
impl<T>type_id(&self) -> TypeId[src]#
pub fnGets the TypeId
of self
. Read more
Borrow<T> for T where T: ?Sized,[src]#
impl<T>borrow(&self) -> &T[src]#
pub fnImmutably borrows from an owned value. Read more
BorrowMut<T> for T where T: ?Sized,[src]#
impl<T>borrow_mut(&mut self) -> &mutT[src]#
pub fnMutably borrows from an owned value. Read more
From<T> for T[src]#
impl<T>from(t: T) -> T[src]#
pub fnPerforms the conversion.
Into<U> for T where U: From<T>,[src]#
impl<T, U>into(self) -> U[src]#
pub fnPerforms the conversion.
TryFrom<U> for T where U: Into<T>,[src]#
impl<T, U>Error = Infallible#
typeThe type returned in the event of a conversion error.
try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]#
pub fnPerforms the conversion.
TryInto<U> for T where U: TryFrom<T>,[src]#
impl<T, U>Error = <U as TryFrom<T>>::Error#
typeThe type returned in the event of a conversion error.
try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]#
pub fnPerforms the conversion.