feat(core): add is_visible API

This commit is contained in:
Lucas Nogueira 2021-05-30 18:06:24 -03:00
parent 5f351622c7
commit 36506c967d
No known key found for this signature in database
GPG Key ID: 2714B66BCFB01F7F
9 changed files with 56 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"api": patch
---
Adds `isVisible` getter on the window API.

7
.changes/is-visible.md Normal file
View File

@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---
Adds `is_visible` getter on Window.

View File

@ -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"

View File

@ -405,6 +405,7 @@ enum WindowMessage {
IsMaximized(Sender<bool>),
IsDecorated(Sender<bool>),
IsResizable(Sender<bool>),
IsVisible(Sender<bool>),
CurrentMonitor(Sender<Option<MonitorHandle>>),
PrimaryMonitor(Sender<Option<MonitorHandle>>),
AvailableMonitors(Sender<Vec<MonitorHandle>>),
@ -548,6 +549,10 @@ impl Dispatch for WryDispatcher {
Ok(dispatcher_getter!(self, WindowMessage::IsResizable))
}
fn is_visible(&self) -> Result<bool> {
Ok(dispatcher_getter!(self, WindowMessage::IsVisible))
}
fn current_monitor(&self) -> Result<Option<Monitor>> {
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) => {

View File

@ -213,6 +213,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
/// Gets the windows current resizable state.
fn is_resizable(&self) -> crate::Result<bool>;
/// Gets the window's current vibility state.
fn is_visible(&self) -> crate::Result<bool>;
/// Returns the monitor on which the window currently resides.
///
/// Returns None if current monitor can't be detected.

View File

@ -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()),

View File

@ -361,6 +361,11 @@ impl<P: Params> Window<P> {
self.window.dispatcher.is_resizable().map_err(Into::into)
}
/// Gets the window's current vibility state.
pub fn is_visible(&self) -> crate::Result<bool> {
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.

View File

@ -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(

View File

@ -372,6 +372,26 @@ class WindowManager {
})
}
/** Gets the window's current resizable state. */
async isResizable(): Promise<boolean> {
return invokeTauriCommand({
__tauriModule: 'Window',
message: {
cmd: 'isResizable'
}
})
}
/** Gets the window's current visible state. */
async isVisible(): Promise<boolean> {
return invokeTauriCommand({
__tauriModule: 'Window',
message: {
cmd: 'isVisible'
}
})
}
// Setters
/**