mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
feat(core): add is_visible
API
This commit is contained in:
parent
5f351622c7
commit
36506c967d
5
.changes/api-is-visible.md
Normal file
5
.changes/api-is-visible.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"api": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adds `isVisible` getter on the window API.
|
7
.changes/is-visible.md
Normal file
7
.changes/is-visible.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"tauri": patch
|
||||||
|
"tauri-runtime": patch
|
||||||
|
"tauri-runtime-wry": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adds `is_visible` getter on Window.
|
@ -22,6 +22,9 @@ members = [
|
|||||||
"examples/updater/src-tauri",
|
"examples/updater/src-tauri",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
tao = { git = "https://github.com/tauri-apps/tao", rev = "a3f533232df25dc30998809094ed5431b449489c" }
|
||||||
|
|
||||||
# default to small, optimized workspace release binaries
|
# default to small, optimized workspace release binaries
|
||||||
[profile.release]
|
[profile.release]
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
@ -405,6 +405,7 @@ enum WindowMessage {
|
|||||||
IsMaximized(Sender<bool>),
|
IsMaximized(Sender<bool>),
|
||||||
IsDecorated(Sender<bool>),
|
IsDecorated(Sender<bool>),
|
||||||
IsResizable(Sender<bool>),
|
IsResizable(Sender<bool>),
|
||||||
|
IsVisible(Sender<bool>),
|
||||||
CurrentMonitor(Sender<Option<MonitorHandle>>),
|
CurrentMonitor(Sender<Option<MonitorHandle>>),
|
||||||
PrimaryMonitor(Sender<Option<MonitorHandle>>),
|
PrimaryMonitor(Sender<Option<MonitorHandle>>),
|
||||||
AvailableMonitors(Sender<Vec<MonitorHandle>>),
|
AvailableMonitors(Sender<Vec<MonitorHandle>>),
|
||||||
@ -548,6 +549,10 @@ impl Dispatch for WryDispatcher {
|
|||||||
Ok(dispatcher_getter!(self, WindowMessage::IsResizable))
|
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>> {
|
fn current_monitor(&self) -> Result<Option<Monitor>> {
|
||||||
Ok(
|
Ok(
|
||||||
dispatcher_getter!(self, WindowMessage::CurrentMonitor)
|
dispatcher_getter!(self, WindowMessage::CurrentMonitor)
|
||||||
@ -1160,6 +1165,7 @@ fn handle_event_loop(
|
|||||||
WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
|
WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
|
||||||
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
|
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
|
||||||
WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).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::CurrentMonitor(tx) => tx.send(window.current_monitor()).unwrap(),
|
||||||
WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(),
|
WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(),
|
||||||
WindowMessage::AvailableMonitors(tx) => {
|
WindowMessage::AvailableMonitors(tx) => {
|
||||||
|
@ -213,6 +213,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
|
|||||||
/// Gets the window’s current resizable state.
|
/// Gets the window’s current resizable state.
|
||||||
fn is_resizable(&self) -> crate::Result<bool>;
|
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 the monitor on which the window currently resides.
|
||||||
///
|
///
|
||||||
/// Returns None if current monitor can't be detected.
|
/// Returns None if current monitor can't be detected.
|
||||||
|
@ -48,6 +48,7 @@ pub enum Cmd {
|
|||||||
IsMaximized,
|
IsMaximized,
|
||||||
IsDecorated,
|
IsDecorated,
|
||||||
IsResizable,
|
IsResizable,
|
||||||
|
IsVisible,
|
||||||
CurrentMonitor,
|
CurrentMonitor,
|
||||||
PrimaryMonitor,
|
PrimaryMonitor,
|
||||||
AvailableMonitors,
|
AvailableMonitors,
|
||||||
@ -134,6 +135,7 @@ impl Cmd {
|
|||||||
Self::IsMaximized => return Ok(window.is_maximized()?.into()),
|
Self::IsMaximized => return Ok(window.is_maximized()?.into()),
|
||||||
Self::IsDecorated => return Ok(window.is_decorated()?.into()),
|
Self::IsDecorated => return Ok(window.is_decorated()?.into()),
|
||||||
Self::IsResizable => return Ok(window.is_resizable()?.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::CurrentMonitor => return Ok(window.current_monitor()?.into()),
|
||||||
Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
|
Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
|
||||||
Self::AvailableMonitors => return Ok(window.available_monitors()?.into()),
|
Self::AvailableMonitors => return Ok(window.available_monitors()?.into()),
|
||||||
|
@ -361,6 +361,11 @@ impl<P: Params> Window<P> {
|
|||||||
self.window.dispatcher.is_resizable().map_err(Into::into)
|
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 the monitor on which the window currently resides.
|
||||||
///
|
///
|
||||||
/// Returns None if current monitor can't be detected.
|
/// Returns None if current monitor can't be detected.
|
||||||
|
@ -45,8 +45,11 @@ fn main() {
|
|||||||
match event.menu_item_id().as_str() {
|
match event.menu_item_id().as_str() {
|
||||||
"toggle" => {
|
"toggle" => {
|
||||||
let window = app.get_window("main").unwrap();
|
let window = app.get_window("main").unwrap();
|
||||||
// TODO: window.is_visible API
|
if window.is_visible().unwrap() {
|
||||||
window.hide().unwrap();
|
window.hide().unwrap();
|
||||||
|
} else {
|
||||||
|
window.show().unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"new" => app
|
"new" => app
|
||||||
.create_window(
|
.create_window(
|
||||||
|
@ -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
|
// Setters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user