Skip to content

Commit

Permalink
feat(core): add is_visible API
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 30, 2021
1 parent 5f35162 commit 36506c9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/api-is-visible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": patch
---

Adds `isVisible` getter on the window API.
7 changes: 7 additions & 0 deletions .changes/is-visible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---

Adds `is_visible` getter on Window.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
/// Gets the window’s 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.
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/src/endpoints/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub enum Cmd {
IsMaximized,
IsDecorated,
IsResizable,
IsVisible,
CurrentMonitor,
PrimaryMonitor,
AvailableMonitors,
Expand Down Expand Up @@ -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()),
Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions examples/api/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down

0 comments on commit 36506c9

Please sign in to comment.