Skip to content

Commit 36506c9

Browse files
committed
feat(core): add is_visible API
1 parent 5f35162 commit 36506c9

File tree

9 files changed

+56
-2
lines changed

9 files changed

+56
-2
lines changed

.changes/api-is-visible.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Adds `isVisible` getter on the window API.

.changes/is-visible.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime": patch
4+
"tauri-runtime-wry": patch
5+
---
6+
7+
Adds `is_visible` getter on Window.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ members = [
2222
"examples/updater/src-tauri",
2323
]
2424

25+
[patch.crates-io]
26+
tao = { git = "https://github.com/tauri-apps/tao", rev = "a3f533232df25dc30998809094ed5431b449489c" }
27+
2528
# default to small, optimized workspace release binaries
2629
[profile.release]
2730
panic = "abort"

core/tauri-runtime-wry/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ enum WindowMessage {
405405
IsMaximized(Sender<bool>),
406406
IsDecorated(Sender<bool>),
407407
IsResizable(Sender<bool>),
408+
IsVisible(Sender<bool>),
408409
CurrentMonitor(Sender<Option<MonitorHandle>>),
409410
PrimaryMonitor(Sender<Option<MonitorHandle>>),
410411
AvailableMonitors(Sender<Vec<MonitorHandle>>),
@@ -548,6 +549,10 @@ impl Dispatch for WryDispatcher {
548549
Ok(dispatcher_getter!(self, WindowMessage::IsResizable))
549550
}
550551

552+
fn is_visible(&self) -> Result<bool> {
553+
Ok(dispatcher_getter!(self, WindowMessage::IsVisible))
554+
}
555+
551556
fn current_monitor(&self) -> Result<Option<Monitor>> {
552557
Ok(
553558
dispatcher_getter!(self, WindowMessage::CurrentMonitor)
@@ -1160,6 +1165,7 @@ fn handle_event_loop(
11601165
WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
11611166
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
11621167
WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).unwrap(),
1168+
WindowMessage::IsVisible(tx) => tx.send(window.is_visible()).unwrap(),
11631169
WindowMessage::CurrentMonitor(tx) => tx.send(window.current_monitor()).unwrap(),
11641170
WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(),
11651171
WindowMessage::AvailableMonitors(tx) => {

core/tauri-runtime/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
213213
/// Gets the window’s current resizable state.
214214
fn is_resizable(&self) -> crate::Result<bool>;
215215

216+
/// Gets the window's current vibility state.
217+
fn is_visible(&self) -> crate::Result<bool>;
218+
216219
/// Returns the monitor on which the window currently resides.
217220
///
218221
/// Returns None if current monitor can't be detected.

core/tauri/src/endpoints/window.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub enum Cmd {
4848
IsMaximized,
4949
IsDecorated,
5050
IsResizable,
51+
IsVisible,
5152
CurrentMonitor,
5253
PrimaryMonitor,
5354
AvailableMonitors,
@@ -134,6 +135,7 @@ impl Cmd {
134135
Self::IsMaximized => return Ok(window.is_maximized()?.into()),
135136
Self::IsDecorated => return Ok(window.is_decorated()?.into()),
136137
Self::IsResizable => return Ok(window.is_resizable()?.into()),
138+
Self::IsVisible => return Ok(window.is_visible()?.into()),
137139
Self::CurrentMonitor => return Ok(window.current_monitor()?.into()),
138140
Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
139141
Self::AvailableMonitors => return Ok(window.available_monitors()?.into()),

core/tauri/src/window.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ impl<P: Params> Window<P> {
361361
self.window.dispatcher.is_resizable().map_err(Into::into)
362362
}
363363

364+
/// Gets the window's current vibility state.
365+
pub fn is_visible(&self) -> crate::Result<bool> {
366+
self.window.dispatcher.is_visible().map_err(Into::into)
367+
}
368+
364369
/// Returns the monitor on which the window currently resides.
365370
///
366371
/// Returns None if current monitor can't be detected.

examples/api/src-tauri/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ fn main() {
4545
match event.menu_item_id().as_str() {
4646
"toggle" => {
4747
let window = app.get_window("main").unwrap();
48-
// TODO: window.is_visible API
49-
window.hide().unwrap();
48+
if window.is_visible().unwrap() {
49+
window.hide().unwrap();
50+
} else {
51+
window.show().unwrap();
52+
}
5053
}
5154
"new" => app
5255
.create_window(

tooling/api/src/window.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,26 @@ class WindowManager {
372372
})
373373
}
374374

375+
/** Gets the window's current resizable state. */
376+
async isResizable(): Promise<boolean> {
377+
return invokeTauriCommand({
378+
__tauriModule: 'Window',
379+
message: {
380+
cmd: 'isResizable'
381+
}
382+
})
383+
}
384+
385+
/** Gets the window's current visible state. */
386+
async isVisible(): Promise<boolean> {
387+
return invokeTauriCommand({
388+
__tauriModule: 'Window',
389+
message: {
390+
cmd: 'isVisible'
391+
}
392+
})
393+
}
394+
375395
// Setters
376396

377397
/**

0 commit comments

Comments
 (0)