diff --git a/.changes/api-is-visible.md b/.changes/api-is-visible.md new file mode 100644 index 00000000000..e3cfd2250f1 --- /dev/null +++ b/.changes/api-is-visible.md @@ -0,0 +1,5 @@ +--- +"api": patch +--- + +Adds `isVisible` getter on the window API. diff --git a/.changes/is-visible.md b/.changes/is-visible.md new file mode 100644 index 00000000000..75a8b4b5be9 --- /dev/null +++ b/.changes/is-visible.md @@ -0,0 +1,7 @@ +--- +"tauri": patch +"tauri-runtime": patch +"tauri-runtime-wry": patch +--- + +Adds `is_visible` getter on Window. diff --git a/Cargo.toml b/Cargo.toml index f6df2dbddd4..6c4a62c7df8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,9 @@ members = [ "examples/updater/src-tauri", ] +[patch.crates-io] +tao = { git = "https://github.com/tauri-apps/tao", rev = "a3f533232df25dc30998809094ed5431b449489c" } + # default to small, optimized workspace release binaries [profile.release] panic = "abort" diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index d85271d7ff0..e39b781b123 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -405,6 +405,7 @@ enum WindowMessage { IsMaximized(Sender), IsDecorated(Sender), IsResizable(Sender), + IsVisible(Sender), CurrentMonitor(Sender>), PrimaryMonitor(Sender>), AvailableMonitors(Sender>), @@ -548,6 +549,10 @@ impl Dispatch for WryDispatcher { Ok(dispatcher_getter!(self, WindowMessage::IsResizable)) } + fn is_visible(&self) -> Result { + Ok(dispatcher_getter!(self, WindowMessage::IsVisible)) + } + fn current_monitor(&self) -> Result> { Ok( dispatcher_getter!(self, WindowMessage::CurrentMonitor) @@ -1160,6 +1165,7 @@ fn handle_event_loop( WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(), WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(), WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).unwrap(), + WindowMessage::IsVisible(tx) => tx.send(window.is_visible()).unwrap(), WindowMessage::CurrentMonitor(tx) => tx.send(window.current_monitor()).unwrap(), WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(), WindowMessage::AvailableMonitors(tx) => { diff --git a/core/tauri-runtime/src/lib.rs b/core/tauri-runtime/src/lib.rs index dce0bd2abd4..19dc89795b6 100644 --- a/core/tauri-runtime/src/lib.rs +++ b/core/tauri-runtime/src/lib.rs @@ -213,6 +213,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static { /// Gets the window’s current resizable state. fn is_resizable(&self) -> crate::Result; + /// Gets the window's current vibility state. + fn is_visible(&self) -> crate::Result; + /// Returns the monitor on which the window currently resides. /// /// Returns None if current monitor can't be detected. diff --git a/core/tauri/src/endpoints/window.rs b/core/tauri/src/endpoints/window.rs index 405e72e474b..546d2bf81cc 100644 --- a/core/tauri/src/endpoints/window.rs +++ b/core/tauri/src/endpoints/window.rs @@ -48,6 +48,7 @@ pub enum Cmd { IsMaximized, IsDecorated, IsResizable, + IsVisible, CurrentMonitor, PrimaryMonitor, AvailableMonitors, @@ -134,6 +135,7 @@ impl Cmd { Self::IsMaximized => return Ok(window.is_maximized()?.into()), Self::IsDecorated => return Ok(window.is_decorated()?.into()), Self::IsResizable => return Ok(window.is_resizable()?.into()), + Self::IsVisible => return Ok(window.is_visible()?.into()), Self::CurrentMonitor => return Ok(window.current_monitor()?.into()), Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()), Self::AvailableMonitors => return Ok(window.available_monitors()?.into()), diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index c5d89060c7c..c19a4b93cba 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -361,6 +361,11 @@ impl Window

{ self.window.dispatcher.is_resizable().map_err(Into::into) } + /// Gets the window's current vibility state. + pub fn is_visible(&self) -> crate::Result { + self.window.dispatcher.is_visible().map_err(Into::into) + } + /// Returns the monitor on which the window currently resides. /// /// Returns None if current monitor can't be detected. diff --git a/examples/api/src-tauri/src/main.rs b/examples/api/src-tauri/src/main.rs index 9cf5264529d..19f88f48a06 100644 --- a/examples/api/src-tauri/src/main.rs +++ b/examples/api/src-tauri/src/main.rs @@ -45,8 +45,11 @@ fn main() { match event.menu_item_id().as_str() { "toggle" => { let window = app.get_window("main").unwrap(); - // TODO: window.is_visible API - window.hide().unwrap(); + if window.is_visible().unwrap() { + window.hide().unwrap(); + } else { + window.show().unwrap(); + } } "new" => app .create_window( diff --git a/tooling/api/src/window.ts b/tooling/api/src/window.ts index 17f886f8155..416093df99e 100644 --- a/tooling/api/src/window.ts +++ b/tooling/api/src/window.ts @@ -372,6 +372,26 @@ class WindowManager { }) } + /** Gets the window's current resizable state. */ + async isResizable(): Promise { + return invokeTauriCommand({ + __tauriModule: 'Window', + message: { + cmd: 'isResizable' + } + }) + } + + /** Gets the window's current visible state. */ + async isVisible(): Promise { + return invokeTauriCommand({ + __tauriModule: 'Window', + message: { + cmd: 'isVisible' + } + }) + } + // Setters /**