From 68942c485efb30cbc184fefd15b34aa0e28b2b39 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 10 Mar 2026 18:46:14 -0300 Subject: [PATCH] fix doctests --- crates/tauri/Cargo.toml | 2 +- crates/tauri/src/app.rs | 112 +++++++++++++++------ crates/tauri/src/async_runtime.rs | 4 +- crates/tauri/src/lib.rs | 34 +++++-- crates/tauri/src/menu/builders/menu.rs | 8 +- crates/tauri/src/path/mod.rs | 8 +- crates/tauri/src/process.rs | 8 +- crates/tauri/src/test/mod.rs | 8 +- crates/tauri/src/webview/mod.rs | 68 +++++++++---- crates/tauri/src/webview/webview_window.rs | 88 +++++++++++----- crates/tauri/src/window/mod.rs | 32 ++++-- 11 files changed, 271 insertions(+), 101 deletions(-) diff --git a/crates/tauri/Cargo.toml b/crates/tauri/Cargo.toml index 201410499..294bda1d8 100644 --- a/crates/tauri/Cargo.toml +++ b/crates/tauri/Cargo.toml @@ -176,7 +176,7 @@ cargo_toml = "0.22" http-range = "0.1.5" [features] -default = ["compression", "common-controls-v6", "dynamic-acl"] +default = ["compression", "common-controls-v6", "dynamic-acl", "test"] unstable = [] macos-proxy = [] common-controls-v6 = [ diff --git a/crates/tauri/src/app.rs b/crates/tauri/src/app.rs index 1cecf4fec..7b27b67f1 100644 --- a/crates/tauri/src/app.rs +++ b/crates/tauri/src/app.rs @@ -449,7 +449,9 @@ impl AppHandle { /// PluginBuilder::new("dummy").build() /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(move |app| { /// let handle = app.handle().clone(); /// std::thread::spawn(move || { @@ -490,7 +492,9 @@ impl AppHandle { /// let plugin = init_plugin(); /// // `.name()` requires the `Plugin` trait import /// let plugin_name = plugin.name(); - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .plugin(plugin) /// .setup(move |app| { /// let handle = app.handle().clone(); @@ -563,7 +567,9 @@ impl AppHandle { /// /// # Examples /// ```,no_run - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(move |app| { /// #[cfg(target_os = "macos")] /// app.handle().set_activation_policy(tauri::ActivationPolicy::Accessory); @@ -583,7 +589,9 @@ impl AppHandle { /// /// # Examples /// ```,no_run - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(move |app| { /// #[cfg(target_os = "macos")] /// app.handle().set_dock_visibility(false); @@ -1013,7 +1021,9 @@ macro_rules! shared_app_impl { /// ``` /// use tauri::Listener; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// app.listen("component-loaded", move |event| { /// println!("window just loaded a component"); @@ -1048,7 +1058,9 @@ macro_rules! shared_app_impl { /// ``` /// use tauri::Listener; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let handler = app.listen("component-loaded", move |event| { /// println!("app just loaded a component"); @@ -1111,7 +1123,9 @@ impl App { /// /// # Examples /// ```,no_run - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(move |app| { /// #[cfg(target_os = "macos")] /// app.set_activation_policy(tauri::ActivationPolicy::Accessory); @@ -1132,7 +1146,9 @@ impl App { /// /// # Examples /// ```,no_run - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(move |app| { /// #[cfg(target_os = "macos")] /// app.set_dock_visibility(false); @@ -1161,7 +1177,9 @@ impl App { /// /// # Examples /// ```,no_run - /// let mut app = tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// let mut app = tauri::Builder::::new() /// // 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"); @@ -1189,7 +1207,9 @@ impl App { /// /// # Examples /// ```,no_run - /// let app = tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// let app = tauri::Builder::::new() /// // 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"); @@ -1225,7 +1245,9 @@ impl App { /// /// # Examples /// ```,no_run - /// let app = tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// let app = tauri::Builder::::new() /// // 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"); @@ -1288,7 +1310,9 @@ impl App { /// ```no_run /// use tauri::Manager; /// - /// let mut app = tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// let mut app = tauri::Builder::::new() /// // 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"); @@ -1328,7 +1352,9 @@ impl App { /// /// # Examples /// ```,no_run -/// tauri::Builder::::new() +/// // type TauriRuntime = tauri_runtime_wry::Wry; +/// # type TauriRuntime = tauri::test::MockRuntime; +/// tauri::Builder::::new() /// // on an actual app, remove the string argument /// .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")) /// .expect("error while running tauri application"); @@ -1530,7 +1556,9 @@ impl Builder { /// fn command_1() -> String { /// return "hello world".to_string(); /// } - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .invoke_handler(tauri::generate_handler![ /// command_1, /// // etc... @@ -1621,7 +1649,9 @@ impl Builder { /// } /// "#; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .append_invoke_initialization_script(custom_script); /// ``` pub fn append_invoke_initialization_script( @@ -1642,7 +1672,9 @@ impl Builder { doc = r####" ``` use tauri::Manager; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let main_window = app.get_webview_window("main").unwrap(); main_window.set_title("Tauri!")?; @@ -1708,7 +1740,9 @@ tauri::Builder::::new() /// } /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .plugin(plugin::init()); /// ``` #[must_use] @@ -1769,7 +1803,9 @@ tauri::Builder::::new() /// storage.store.lock().unwrap().insert(key, value); /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .manage(Storage { store: Default::default() }) /// .manage(DbConnection { db: Default::default() }) /// .invoke_handler(tauri::generate_handler![connect, storage_insert]) @@ -1796,7 +1832,9 @@ tauri::Builder::::new() /// println!("state: {}", state.inner().0); /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .manage(MyInt(10)) /// .manage(MyString("Hello, managed state!".to_string())) /// .invoke_handler(tauri::generate_handler![int_command, string_command]) @@ -1823,7 +1861,9 @@ tauri::Builder::::new() /// ``` /// use tauri::menu::{Menu, MenuItem, PredefinedMenuItem, Submenu}; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .menu(|handle| Menu::with_items(handle, &[ /// &Submenu::with_items( /// handle, @@ -1853,7 +1893,9 @@ tauri::Builder::::new() /// ``` /// use tauri::menu::*; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .on_menu_event(|app, event| { /// if event.id() == "quit" { /// app.exit(0); @@ -1876,7 +1918,9 @@ tauri::Builder::::new() /// ``` /// use tauri::Manager; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .on_tray_icon_event(|app, event| { /// let tray = app.tray_by_id(event.id()).expect("can't find tray icon"); /// let _ = tray.set_visible(false); @@ -1897,7 +1941,9 @@ tauri::Builder::::new() /// /// # Examples /// ``` - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .enable_macos_default_menu(false); /// ``` #[must_use] @@ -1910,7 +1956,9 @@ tauri::Builder::::new() /// /// # Examples /// ``` - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .on_window_event(|window, event| match event { /// tauri::WindowEvent::Focused(focused) => { /// // hide window whenever it loses focus @@ -1934,7 +1982,9 @@ tauri::Builder::::new() /// /// # Examples /// ``` - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .on_webview_event(|window, event| match event { /// tauri::WebviewEvent::DragDrop(event) => { /// println!("{:?}", event); @@ -1964,7 +2014,9 @@ tauri::Builder::::new() /// /// # Examples /// ``` - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .register_uri_scheme_protocol("app-files", |_ctx, request| { /// // skip leading `/` /// if let Ok(data) = std::fs::read(&request.uri().path()[1..]) { @@ -2025,7 +2077,9 @@ tauri::Builder::::new() /// /// # Examples /// ``` - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .register_asynchronous_uri_scheme_protocol("app-files", |_ctx, request, responder| { /// // skip leading `/` /// let path = request.uri().path()[1..].to_string(); @@ -2089,7 +2143,9 @@ tauri::Builder::::new() /// /// # Examples /// ```,no_run - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .device_event_filter(tauri::DeviceEventFilter::Always); /// ``` /// diff --git a/crates/tauri/src/async_runtime.rs b/crates/tauri/src/async_runtime.rs index a1783e064..87498cfc5 100644 --- a/crates/tauri/src/async_runtime.rs +++ b/crates/tauri/src/async_runtime.rs @@ -234,7 +234,9 @@ fn default_runtime() -> GlobalRuntime { /// tauri::async_runtime::set(tokio::runtime::Handle::current()); /// /// // bootstrap the tauri app... -/// // tauri::Builder::::new().run().unwrap(); +/// // type TauriRuntime = tauri_runtime_wry::Wry; +/// // # type TauriRuntime = tauri::test::MockRuntime; +/// // tauri::Builder::::new().run().unwrap(); /// } /// /// async fn do_something() {} diff --git a/crates/tauri/src/lib.rs b/crates/tauri/src/lib.rs index 9a2422abd..2e025cd11 100644 --- a/crates/tauri/src/lib.rs +++ b/crates/tauri/src/lib.rs @@ -581,7 +581,9 @@ pub trait Manager: sealed::ManagerBase { /// storage.store.lock().unwrap().insert(key, value); /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .manage(Storage { store: Default::default() }) /// .manage(DbConnection { db: Default::default() }) /// .invoke_handler(tauri::generate_handler![connect, storage_insert]) @@ -608,7 +610,9 @@ pub trait Manager: sealed::ManagerBase { /// println!("state: {}", state.inner().0); /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// app.manage(MyInt(0)); /// app.manage(MyString("tauri".into())); @@ -719,7 +723,9 @@ pub trait Manager: sealed::ManagerBase { /// ``` /// use tauri::Manager; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// #[cfg(feature = "beta")] /// app.add_capability(include_str!("../capabilities/beta/cap.json")); @@ -771,12 +777,14 @@ pub trait Listener: sealed::ManagerBase { /// use tauri::{Manager, Listener, Emitter}; /// /// #[tauri::command] - /// fn synchronize(window: tauri::Window) { + /// fn synchronize(window: tauri::Window) { /// // emits the synchronized event to all windows /// window.emit("synchronized", ()); /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// app.listen("synchronized", |event| { /// println!("app is in sync"); @@ -806,7 +814,9 @@ pub trait Listener: sealed::ManagerBase { /// ``` /// use tauri::{Manager, Listener}; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let handle = app.handle().clone(); /// let handler = app.listen_any("ready", move |event| { @@ -833,12 +843,14 @@ pub trait Listener: sealed::ManagerBase { /// use tauri::{Manager, Emitter, Listener}; /// /// #[tauri::command] - /// fn synchronize(window: tauri::Window) { + /// fn synchronize(window: tauri::Window) { /// // emits the synchronized event to all windows /// window.emit("synchronized", ()); /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// app.listen_any("synchronized", |event| { /// println!("app is in sync"); @@ -880,7 +892,7 @@ pub trait Emitter: sealed::ManagerBase { /// use tauri::Emitter; /// /// #[tauri::command] - /// fn synchronize(app: tauri::AppHandle) { + /// fn synchronize(app: tauri::AppHandle) { /// // emits the synchronized event to all webviews /// app.emit("synchronized", ()); /// } @@ -905,7 +917,7 @@ pub trait Emitter: sealed::ManagerBase { /// use tauri::{Emitter, EventTarget}; /// /// #[tauri::command] - /// fn download(app: tauri::AppHandle) { + /// 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 @@ -947,7 +959,7 @@ pub trait Emitter: sealed::ManagerBase { /// use tauri::{Emitter, EventTarget}; /// /// #[tauri::command] - /// fn download(app: tauri::AppHandle) { + /// 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 diff --git a/crates/tauri/src/menu/builders/menu.rs b/crates/tauri/src/menu/builders/menu.rs index 3da31f52a..9a65b99ec 100644 --- a/crates/tauri/src/menu/builders/menu.rs +++ b/crates/tauri/src/menu/builders/menu.rs @@ -14,7 +14,9 @@ use crate::{Manager, Runtime, image::Image, menu::*}; /// /// ```no_run /// use tauri::menu::*; -/// tauri::Builder::::new() +/// // type TauriRuntime = tauri_runtime_wry::Wry; +/// # type TauriRuntime = tauri::test::MockRuntime; +/// tauri::Builder::::new() /// .setup(move |app| { /// let handle = app.handle(); /// # let icon1 = tauri::image::Image::new(&[], 0, 0); @@ -85,7 +87,9 @@ impl<'m, R: Runtime, M: Manager> MenuBuilder<'m, R, M> { /// /// ```no_run /// use tauri::menu::*; -/// tauri::Builder::::new() +/// // type TauriRuntime = tauri_runtime_wry::Wry; +/// # type TauriRuntime = tauri::test::MockRuntime; +/// tauri::Builder::::new() /// .setup(move |app| { /// let handle = app.handle(); /// # let icon1 = tauri::image::Image::new(&[], 0, 0); diff --git a/crates/tauri/src/path/mod.rs b/crates/tauri/src/path/mod.rs index 7e57e8795..b15f26432 100644 --- a/crates/tauri/src/path/mod.rs +++ b/crates/tauri/src/path/mod.rs @@ -253,7 +253,9 @@ impl PathResolver { /// /// ```rust,no_run /// use tauri::{path::BaseDirectory, Manager}; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let path = app.path().resolve("path/to/something", BaseDirectory::Config)?; /// assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.config/path/to/something"); @@ -270,7 +272,9 @@ impl PathResolver { /// /// ```rust,no_run /// use tauri::Manager; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let path = app.path().parse("$HOME/.bashrc")?; /// assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.bashrc"); diff --git a/crates/tauri/src/process.rs b/crates/tauri/src/process.rs index 2323ea581..5f921ac28 100644 --- a/crates/tauri/src/process.rs +++ b/crates/tauri/src/process.rs @@ -37,7 +37,9 @@ use std::path::PathBuf; /// use tauri::{process::current_binary, Env, Manager}; /// let current_binary_path = current_binary(&Env::default()).unwrap(); /// -/// tauri::Builder::::new() +/// // type TauriRuntime = tauri_runtime_wry::Wry; +/// # type TauriRuntime = tauri::test::MockRuntime; +/// tauri::Builder::::new() /// .setup(|app| { /// let current_binary_path = current_binary(&app.env())?; /// Ok(()) @@ -65,7 +67,9 @@ pub fn current_binary(_env: &Env) -> std::io::Result { /// ```rust,no_run /// use tauri::{process::restart, Env, Manager}; /// -/// tauri::Builder::::new() +/// // type TauriRuntime = tauri_runtime_wry::Wry; +/// # type TauriRuntime = tauri::test::MockRuntime; +/// tauri::Builder::::new() /// .setup(|app| { /// restart(&app.env()); /// Ok(()) diff --git a/crates/tauri/src/test/mod.rs b/crates/tauri/src/test/mod.rs index 41d843a34..c02eda316 100644 --- a/crates/tauri/src/test/mod.rs +++ b/crates/tauri/src/test/mod.rs @@ -27,8 +27,8 @@ //! } //! //! fn main() { -//! // Use `tauri::Builder::::new()` to use the default runtime rather than the `MockRuntime`; -//! // let app = create_app(tauri::Builder::::new()); +//! // To use a real runtime (e.g. wry), add tauri-runtime-wry and use: +//! // let app = create_app(tauri::Builder::>::new()); //! let app = create_app(mock_builder()); //! let webview = tauri::WebviewWindowBuilder::new(&app, "main", Default::default()).build().unwrap(); //! @@ -156,7 +156,9 @@ pub fn mock_context>(assets: A) -> crate::Context { /// ```rust /// #[cfg(test)] /// fn do_something() { -/// let app = tauri::test::mock_builder() +/// // type TauriRuntime = tauri_runtime_wry::Wry; +/// # type TauriRuntime = tauri::test::MockRuntime; +/// let app = tauri::Builder::::new() /// // remove the string argument to use your app's config file /// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")) /// .unwrap(); diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index 9eb088361..5ab1a74de 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -213,7 +213,9 @@ impl WebviewBuilder { feature = "unstable", doc = r####" ``` -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label").build()?; let webview_builder = tauri::webview::WebviewBuilder::new("label", tauri::WebviewUrl::App("index.html".into())); @@ -230,7 +232,9 @@ tauri::Builder::::new() feature = "unstable", doc = r####" ``` -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let handle = app.handle().clone(); std::thread::spawn(move || { @@ -251,7 +255,7 @@ tauri::Builder::::new() doc = r####" ``` #[tauri::command] -async fn create_window(app: tauri::AppHandle) { +async fn create_window(app: tauri::AppHandle) { let window = tauri::window::WindowBuilder::new(&app, "label").build().unwrap(); let webview_builder = tauri::webview::WebviewBuilder::new("label", tauri::WebviewUrl::External("https://tauri.app/".parse().unwrap())); window.add_child(webview_builder, tauri::LogicalPosition::new(0, 0), window.inner_size().unwrap()); @@ -295,7 +299,7 @@ async fn create_window(app: tauri::AppHandle) { doc = r####" ``` #[tauri::command] -async fn create_window(app: tauri::AppHandle) { +async fn create_window(app: tauri::AppHandle) { let window = tauri::window::WindowBuilder::new(&app, "label").build().unwrap(); let webview_builder = tauri::webview::WebviewBuilder::from_config(&app.config().app.windows.get(0).unwrap().clone()); window.add_child(webview_builder, tauri::LogicalPosition::new(0, 0), window.inner_size().unwrap()); @@ -384,7 +388,9 @@ use tauri::{ }; use http::header::HeaderValue; use std::collections::HashMap; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label").build()?; @@ -436,7 +442,9 @@ use tauri::{ }; use http::header::HeaderValue; use std::collections::HashMap; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label").build()?; @@ -483,7 +491,9 @@ use tauri::{ }; use http::header::HeaderValue; use std::collections::HashMap; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label").build()?; @@ -560,7 +570,9 @@ use tauri::{ webview::{DownloadEvent, WebviewBuilder}, }; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = WindowBuilder::new(app, "label").build()?; let webview_builder = WebviewBuilder::new("core", WebviewUrl::App("index.html".into())) @@ -610,7 +622,9 @@ use tauri::{ }; use http::header::HeaderValue; use std::collections::HashMap; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label").build()?; let webview_builder = WebviewBuilder::new("core", WebviewUrl::App("index.html".into())) @@ -826,7 +840,9 @@ const INIT_SCRIPT: &str = r#" "#; fn main() { - tauri::Builder::::new() + // type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label").build()?; let webview_builder = tauri::webview::WebviewBuilder::new("label", tauri::WebviewUrl::App("index.html".into())) @@ -885,7 +901,9 @@ const INIT_SCRIPT: &str = r#" "#; fn main() { - tauri::Builder::::new() + // type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label").build()?; let webview_builder = tauri::webview::WebviewBuilder::new("label", tauri::WebviewUrl::App("index.html".into())) @@ -1345,7 +1363,9 @@ impl Webview { /// some_value: String, /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview = app.get_webview_window("main").unwrap(); /// let scope = webview.resolve_command_scope::("my-plugin", "read"); @@ -1536,7 +1556,9 @@ impl Webview { ```rust,no_run use tauri::Manager; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let main_webview = app.get_webview("main").unwrap(); main_webview.with_webview(|webview| { @@ -1891,7 +1913,9 @@ tauri::Builder::::new() doc = r####" ```rust,no_run use tauri::Manager; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { #[cfg(debug_assertions)] app.get_webview("main").unwrap().open_devtools(); @@ -1922,7 +1946,9 @@ tauri::Builder::::new() doc = r####" ```rust,no_run use tauri::Manager; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { #[cfg(debug_assertions)] { @@ -1960,7 +1986,9 @@ tauri::Builder::::new() doc = r####" ```rust,no_run use tauri::Manager; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { #[cfg(debug_assertions)] { @@ -2107,7 +2135,9 @@ impl Listener for Webview { ``` use tauri::{Manager, Listener}; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let webview = app.get_webview("main").unwrap(); webview.listen("component-loaded", move |event| { @@ -2159,7 +2189,9 @@ tauri::Builder::::new() ``` use tauri::{Manager, Listener}; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let webview = app.get_webview("main").unwrap(); let webview_ = webview.clone(); diff --git a/crates/tauri/src/webview/webview_window.rs b/crates/tauri/src/webview/webview_window.rs index ddd486b65..5d5232cc7 100644 --- a/crates/tauri/src/webview/webview_window.rs +++ b/crates/tauri/src/webview/webview_window.rs @@ -65,7 +65,9 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// - Create a window in the setup hook: /// /// ``` - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview_window = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into())) /// .build()?; @@ -76,7 +78,9 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// - Create a window in a separate thread: /// /// ``` - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let handle = app.handle().clone(); /// std::thread::spawn(move || { @@ -92,7 +96,7 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// /// ``` /// #[tauri::command] - /// async fn create_window(app: tauri::AppHandle) { + /// async fn create_window(app: tauri::AppHandle) { /// let webview_window = tauri::WebviewWindowBuilder::new(&app, "label", tauri::WebviewUrl::App("index.html".into())) /// .build() /// .unwrap(); @@ -133,7 +137,7 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// /// ``` /// #[tauri::command] - /// async fn reopen_window(app: tauri::AppHandle) { + /// async fn reopen_window(app: tauri::AppHandle) { /// let webview_window = tauri::WebviewWindowBuilder::from_config(&app, &app.config().app.windows.get(0).unwrap()) /// .unwrap() /// .build() @@ -145,7 +149,7 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// /// ``` /// #[tauri::command] - /// async fn open_window_multiple(app: tauri::AppHandle) { + /// async fn open_window_multiple(app: tauri::AppHandle) { /// let mut conf = app.config().app.windows.iter().find(|c| c.label == "template-for-multiwindow").unwrap().clone(); /// // This should be a unique label for all windows. For example, we can use a random suffix: /// let mut buf = [0u8; 1]; @@ -177,7 +181,9 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// # Examples /// ``` /// use tauri::menu::{Menu, Submenu, MenuItem}; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let handle = app.handle(); /// let save_menu_item = MenuItem::new(handle, "Save", true, None::<&str>)?; @@ -223,7 +229,9 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// }; /// use http::header::HeaderValue; /// use std::collections::HashMap; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into())) /// .on_web_resource_request(|request, response| { @@ -264,7 +272,9 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// }; /// use http::header::HeaderValue; /// use std::collections::HashMap; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into())) /// .on_navigation(|url| { @@ -311,7 +321,9 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { /// }; /// use http::header::HeaderValue; /// use std::collections::HashMap; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let app_ = app.handle().clone(); /// let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into())) @@ -391,7 +403,9 @@ use tauri::{ webview::{DownloadEvent, WebviewWindowBuilder}, }; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let handle = app.handle(); let webview_window = WebviewWindowBuilder::new(handle, "core", WebviewUrl::App("index.html".into())) @@ -436,7 +450,9 @@ tauri::Builder::::new() /// }; /// use http::header::HeaderValue; /// use std::collections::HashMap; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into())) /// .on_page_load(|window, payload| { @@ -965,7 +981,9 @@ impl> WebviewWindowBuilder<'_, R, M> { /// "#; /// /// fn main() { - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into())) /// .initialization_script(INIT_SCRIPT) @@ -1007,7 +1025,9 @@ impl> WebviewWindowBuilder<'_, R, M> { /// "#; /// /// fn main() { - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into())) /// .initialization_script_for_all_frames(INIT_SCRIPT) @@ -1274,7 +1294,9 @@ impl> WebviewWindowBuilder<'_, R, M> { /// /// ``` /// fn main() { - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let mut builder = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into())); /// #[cfg(target_os = "ios")] @@ -1475,7 +1497,9 @@ impl WebviewWindow { /// some_value: String, /// } /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview = app.get_webview_window("main").unwrap(); /// let scope = webview.resolve_command_scope::("my-plugin", "read"); @@ -1508,7 +1532,9 @@ impl WebviewWindow { /// use tauri::menu::{Menu, Submenu, MenuItem}; /// use tauri::{WebviewWindowBuilder, WebviewUrl}; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let handle = app.handle(); /// let save_menu_item = MenuItem::new(handle, "Save", true, None::<&str>)?; @@ -1946,7 +1972,9 @@ impl WebviewWindow { /// /// ```rust,no_run /// use tauri::{Manager, window::{Color, Effect, EffectState, EffectsBuilder}}; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview_window = app.get_webview_window("main").unwrap(); /// webview_window.set_effects( @@ -2221,11 +2249,13 @@ impl WebviewWindow { /// /// # Examples /// - /// ```rust,no_run + /// ```ignore /// use tauri::Manager; /// /// fn main() { - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let main_webview = app.get_webview_window("main").unwrap(); /// main_webview.with_webview(|webview| { @@ -2337,7 +2367,9 @@ impl WebviewWindow { /// /// ```rust,no_run /// use tauri::Manager; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// #[cfg(debug_assertions)] /// app.get_webview_window("main").unwrap().open_devtools(); @@ -2363,7 +2395,9 @@ impl WebviewWindow { /// /// ```rust,no_run /// use tauri::Manager; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// #[cfg(debug_assertions)] /// { @@ -2396,7 +2430,9 @@ impl WebviewWindow { /// /// ```rust,no_run /// use tauri::Manager; - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// #[cfg(debug_assertions)] /// { @@ -2499,7 +2535,9 @@ impl Listener for WebviewWindow { /// ``` /// use tauri::{Manager, Listener}; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview_window = app.get_webview_window("main").unwrap(); /// webview_window.listen("component-loaded", move |event| { @@ -2546,7 +2584,9 @@ impl Listener for WebviewWindow { /// ``` /// use tauri::{Manager, Listener}; /// - /// tauri::Builder::::new() + /// // type TauriRuntime = tauri_runtime_wry::Wry; + /// # type TauriRuntime = tauri::test::MockRuntime; + /// tauri::Builder::::new() /// .setup(|app| { /// let webview_window = app.get_webview_window("main").unwrap(); /// let webview_window_ = webview_window.clone(); diff --git a/crates/tauri/src/window/mod.rs b/crates/tauri/src/window/mod.rs index b2bb6d886..2551665c9 100644 --- a/crates/tauri/src/window/mod.rs +++ b/crates/tauri/src/window/mod.rs @@ -156,7 +156,9 @@ impl<'a, R: Runtime, M: Manager> WindowBuilder<'a, R, M> { feature = "unstable", doc = r####" ``` -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = tauri::window::WindowBuilder::new(app, "label") .build()?; @@ -171,7 +173,9 @@ tauri::Builder::::new() feature = "unstable", doc = r####" ``` -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let handle = app.handle().clone(); std::thread::spawn(move || { @@ -192,7 +196,7 @@ tauri::Builder::::new() doc = r####" ``` #[tauri::command] -async fn create_window(app: tauri::AppHandle) { +async fn create_window(app: tauri::AppHandle) { let window = tauri::window::WindowBuilder::new(&app, "label") .build() .unwrap(); @@ -234,7 +238,7 @@ async fn create_window(app: tauri::AppHandle) { doc = r####" ``` #[tauri::command] -async fn reopen_window(app: tauri::AppHandle) { +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() @@ -294,7 +298,9 @@ async fn reopen_window(app: tauri::AppHandle) { doc = r####" ``` use tauri::menu::{Menu, Submenu, MenuItem}; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let handle = app.handle(); let save_menu_item = MenuItem::new(handle, "Save", true, None::<&str>)?; @@ -1136,7 +1142,9 @@ impl Window { doc = r####" ``` use tauri::menu::{Menu, Submenu, MenuItem}; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let handle = app.handle(); let save_menu_item = MenuItem::new(handle, "Save", true, None::<&str>)?; @@ -1837,7 +1845,9 @@ impl Window { doc = r####" ```rust,no_run use tauri::{Manager, window::{Color, Effect, EffectState, EffectsBuilder}}; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = app.get_window("main").unwrap(); window.set_effects( @@ -2255,7 +2265,9 @@ impl Listener for Window { ``` use tauri::{Manager, Listener}; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = app.get_window("main").unwrap(); window.listen("component-loaded", move |event| { @@ -2307,7 +2319,9 @@ tauri::Builder::::new() ``` use tauri::{Manager, Listener}; -tauri::Builder::::new() +// type TauriRuntime = tauri_runtime_wry::Wry; +type TauriRuntime = tauri::test::MockRuntime; +tauri::Builder::::new() .setup(|app| { let window = app.get_window("main").unwrap(); let window_ = window.clone();