feat: add is_minimized (fix #3878) (#5618)

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
fixes https://github.com/tauri-apps/tauri/issues/3878
This commit is contained in:
crpz1 2022-12-13 00:34:19 +11:00 committed by GitHub
parent eaf0d71779
commit 62144ef3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 4 deletions

8
.changes/is-minimized.md Normal file
View File

@ -0,0 +1,8 @@
---
"tauri": minor
"tauri-runtime": minor
"tauri-runtime-wry": minor
"api": minor
---
Add `is_minimized()` window method.

View File

@ -1023,6 +1023,7 @@ pub enum WindowMessage {
InnerSize(Sender<PhysicalSize<u32>>),
OuterSize(Sender<PhysicalSize<u32>>),
IsFullscreen(Sender<bool>),
IsMinimized(Sender<bool>),
IsMaximized(Sender<bool>),
IsDecorated(Sender<bool>),
IsResizable(Sender<bool>),
@ -1239,6 +1240,10 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
window_getter!(self, WindowMessage::IsFullscreen)
}
fn is_minimized(&self) -> Result<bool> {
window_getter!(self, WindowMessage::IsMinimized)
}
fn is_maximized(&self) -> Result<bool> {
window_getter!(self, WindowMessage::IsMaximized)
}
@ -2339,6 +2344,7 @@ fn handle_user_message<T: UserEvent>(
.send(PhysicalSizeWrapper(window.outer_size()).into())
.unwrap(),
WindowMessage::IsFullscreen(tx) => tx.send(window.fullscreen().is_some()).unwrap(),
WindowMessage::IsMinimized(tx) => tx.send(window.is_minimized()).unwrap(),
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(),

View File

@ -522,6 +522,9 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
/// Gets the window's current fullscreen state.
fn is_fullscreen(&self) -> Result<bool>;
/// Gets the window's current minimized state.
fn is_minimized(&self) -> Result<bool>;
/// Gets the window's current maximized state.
fn is_maximized(&self) -> Result<bool>;

File diff suppressed because one or more lines are too long

View File

@ -63,6 +63,7 @@ pub enum WindowManagerCmd {
InnerSize,
OuterSize,
IsFullscreen,
IsMinimized,
IsMaximized,
IsDecorated,
IsResizable,
@ -253,6 +254,7 @@ impl Cmd {
WindowManagerCmd::InnerSize => return Ok(window.inner_size()?.into()),
WindowManagerCmd::OuterSize => return Ok(window.outer_size()?.into()),
WindowManagerCmd::IsFullscreen => return Ok(window.is_fullscreen()?.into()),
WindowManagerCmd::IsMinimized => return Ok(window.is_minimized()?.into()),
WindowManagerCmd::IsMaximized => return Ok(window.is_maximized()?.into()),
WindowManagerCmd::IsDecorated => return Ok(window.is_decorated()?.into()),
WindowManagerCmd::IsResizable => return Ok(window.is_resizable()?.into()),

View File

@ -359,6 +359,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
Ok(false)
}
fn is_minimized(&self) -> Result<bool> {
Ok(false)
}
fn is_maximized(&self) -> Result<bool> {
Ok(false)
}

View File

@ -888,6 +888,11 @@ impl<R: Runtime> Window<R> {
self.window.dispatcher.is_fullscreen().map_err(Into::into)
}
/// Gets the window's current minimized state.
pub fn is_minimized(&self) -> crate::Result<bool> {
self.window.dispatcher.is_minimized().map_err(Into::into)
}
/// Gets the window's current maximized state.
pub fn is_maximized(&self) -> crate::Result<bool> {
self.window.dispatcher.is_maximized().map_err(Into::into)

View File

@ -579,6 +579,31 @@ class WindowManager extends WebviewWindowHandle {
})
}
/**
* Gets the window's current minimized state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const minimized = await appWindow.isMinimized();
* ```
*
* @since 1.3.0
* */
async isMinimized(): Promise<boolean> {
return invokeTauriCommand({
__tauriModule: 'Window',
message: {
cmd: 'manage',
data: {
label: this.label,
cmd: {
type: 'isMinimized'
}
}
}
})
}
/**
* Gets the window's current maximized state.
* @example