Skip to content

Commit

Permalink
feat: add is_minimized (fix #3878) (#5618)
Browse files Browse the repository at this point in the history
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
fixes #3878
  • Loading branch information
crpz1 committed Dec 12, 2022
1 parent eaf0d71 commit 62144ef
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changes/is-minimized.md
@@ -0,0 +1,8 @@
---
"tauri": minor
"tauri-runtime": minor
"tauri-runtime-wry": minor
"api": minor
---

Add `is_minimized()` window method.
6 changes: 6 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Expand Up @@ -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>),
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/src/lib.rs
Expand Up @@ -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>;

Expand Down
8 changes: 4 additions & 4 deletions core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions core/tauri/src/endpoints/window.rs
Expand Up @@ -63,6 +63,7 @@ pub enum WindowManagerCmd {
InnerSize,
OuterSize,
IsFullscreen,
IsMinimized,
IsMaximized,
IsDecorated,
IsResizable,
Expand Down Expand Up @@ -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()),
Expand Down
4 changes: 4 additions & 0 deletions core/tauri/src/test/mock_runtime.rs
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/window.rs
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions tooling/api/src/window.ts
Expand Up @@ -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
Expand Down

0 comments on commit 62144ef

Please sign in to comment.