Struct tauri::window::WindowBuilder
source · pub struct WindowBuilder<'a, R: Runtime, M: Manager<R>> { /* private fields */ }
Available on crate feature
unstable
only.Expand description
A builder for a window managed by Tauri.
Implementations§
source§impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
sourcepub fn new<L: Into<String>>(manager: &'a M, label: L) -> Self
pub fn new<L: Into<String>>(manager: &'a M, label: L) -> Self
Initializes a window builder with the given window label.
§Known issues
On Windows, this function deadlocks when used in a synchronous command, see the Webview2 issue.
You should use async
commands when creating windows.
§Examples
- Create a window in the setup hook:
tauri::Builder::default()
.setup(|app| {
let window = tauri::window::WindowBuilder::new(app, "label")
.build()?;
Ok(())
});
- Create a window in a separate thread:
tauri::Builder::default()
.setup(|app| {
let handle = app.handle().clone();
std::thread::spawn(move || {
let window = tauri::window::WindowBuilder::new(&handle, "label")
.build()
.unwrap();
});
Ok(())
});
- Create a window in a command:
#[tauri::command]
async fn create_window(app: tauri::AppHandle) {
let window = tauri::window::WindowBuilder::new(&app, "label")
.build()
.unwrap();
}
sourcepub fn from_config(manager: &'a M, config: &WindowConfig) -> Result<Self>
pub fn from_config(manager: &'a M, config: &WindowConfig) -> Result<Self>
Initializes a window builder from a WindowConfig
from tauri.conf.json.
Keep in mind that you can’t create 2 windows with the same label
so make sure
that the initial window was closed or change the label of the new WindowBuilder
.
§Known issues
On Windows, this function deadlocks when used in a synchronous command, see the Webview2 issue.
You should use async
commands when creating windows.
§Examples
- Create a window in a command:
#[tauri::command]
async fn reopen_window(app: tauri::AppHandle) {
let window = tauri::window::WindowBuilder::from_config(&app, &app.config().app.windows.get(0).unwrap().clone())
.unwrap()
.build()
.unwrap();
}
Trait Implementations§
Auto Trait Implementations§
impl<'a, R, M> Freeze for WindowBuilder<'a, R, M>where
<<R as Runtime<EventLoopMessage>>::WindowDispatcher as WindowDispatch<EventLoopMessage>>::WindowBuilder: Freeze,
impl<'a, R, M> RefUnwindSafe for WindowBuilder<'a, R, M>where
<<R as Runtime<EventLoopMessage>>::WindowDispatcher as WindowDispatch<EventLoopMessage>>::WindowBuilder: RefUnwindSafe,
M: RefUnwindSafe,
impl<'a, R, M> Send for WindowBuilder<'a, R, M>where
<<R as Runtime<EventLoopMessage>>::WindowDispatcher as WindowDispatch<EventLoopMessage>>::WindowBuilder: Send,
M: Sync,
impl<'a, R, M> Sync for WindowBuilder<'a, R, M>where
<<R as Runtime<EventLoopMessage>>::WindowDispatcher as WindowDispatch<EventLoopMessage>>::WindowBuilder: Sync,
M: Sync,
impl<'a, R, M> Unpin for WindowBuilder<'a, R, M>where
<<R as Runtime<EventLoopMessage>>::WindowDispatcher as WindowDispatch<EventLoopMessage>>::WindowBuilder: Unpin,
impl<'a, R, M> UnwindSafe for WindowBuilder<'a, R, M>where
<<R as Runtime<EventLoopMessage>>::WindowDispatcher as WindowDispatch<EventLoopMessage>>::WindowBuilder: UnwindSafe,
M: RefUnwindSafe,
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
Mutably borrows from an owned value. Read more