Skip to content

Commit 62144ef

Browse files
crpz1amrbashirlucasfernog
authored
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 #3878
1 parent eaf0d71 commit 62144ef

File tree

8 files changed

+57
-4
lines changed

8 files changed

+57
-4
lines changed

.changes/is-minimized.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": minor
3+
"tauri-runtime": minor
4+
"tauri-runtime-wry": minor
5+
"api": minor
6+
---
7+
8+
Add `is_minimized()` window method.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ pub enum WindowMessage {
10231023
InnerSize(Sender<PhysicalSize<u32>>),
10241024
OuterSize(Sender<PhysicalSize<u32>>),
10251025
IsFullscreen(Sender<bool>),
1026+
IsMinimized(Sender<bool>),
10261027
IsMaximized(Sender<bool>),
10271028
IsDecorated(Sender<bool>),
10281029
IsResizable(Sender<bool>),
@@ -1239,6 +1240,10 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
12391240
window_getter!(self, WindowMessage::IsFullscreen)
12401241
}
12411242

1243+
fn is_minimized(&self) -> Result<bool> {
1244+
window_getter!(self, WindowMessage::IsMinimized)
1245+
}
1246+
12421247
fn is_maximized(&self) -> Result<bool> {
12431248
window_getter!(self, WindowMessage::IsMaximized)
12441249
}
@@ -2339,6 +2344,7 @@ fn handle_user_message<T: UserEvent>(
23392344
.send(PhysicalSizeWrapper(window.outer_size()).into())
23402345
.unwrap(),
23412346
WindowMessage::IsFullscreen(tx) => tx.send(window.fullscreen().is_some()).unwrap(),
2347+
WindowMessage::IsMinimized(tx) => tx.send(window.is_minimized()).unwrap(),
23422348
WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
23432349
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
23442350
WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).unwrap(),

core/tauri-runtime/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
522522
/// Gets the window's current fullscreen state.
523523
fn is_fullscreen(&self) -> Result<bool>;
524524

525+
/// Gets the window's current minimized state.
526+
fn is_minimized(&self) -> Result<bool>;
527+
525528
/// Gets the window's current maximized state.
526529
fn is_maximized(&self) -> Result<bool>;
527530

core/tauri/scripts/bundle.global.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/endpoints/window.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub enum WindowManagerCmd {
6363
InnerSize,
6464
OuterSize,
6565
IsFullscreen,
66+
IsMinimized,
6667
IsMaximized,
6768
IsDecorated,
6869
IsResizable,
@@ -253,6 +254,7 @@ impl Cmd {
253254
WindowManagerCmd::InnerSize => return Ok(window.inner_size()?.into()),
254255
WindowManagerCmd::OuterSize => return Ok(window.outer_size()?.into()),
255256
WindowManagerCmd::IsFullscreen => return Ok(window.is_fullscreen()?.into()),
257+
WindowManagerCmd::IsMinimized => return Ok(window.is_minimized()?.into()),
256258
WindowManagerCmd::IsMaximized => return Ok(window.is_maximized()?.into()),
257259
WindowManagerCmd::IsDecorated => return Ok(window.is_decorated()?.into()),
258260
WindowManagerCmd::IsResizable => return Ok(window.is_resizable()?.into()),

core/tauri/src/test/mock_runtime.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
359359
Ok(false)
360360
}
361361

362+
fn is_minimized(&self) -> Result<bool> {
363+
Ok(false)
364+
}
365+
362366
fn is_maximized(&self) -> Result<bool> {
363367
Ok(false)
364368
}

core/tauri/src/window.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,11 @@ impl<R: Runtime> Window<R> {
888888
self.window.dispatcher.is_fullscreen().map_err(Into::into)
889889
}
890890

891+
/// Gets the window's current minimized state.
892+
pub fn is_minimized(&self) -> crate::Result<bool> {
893+
self.window.dispatcher.is_minimized().map_err(Into::into)
894+
}
895+
891896
/// Gets the window's current maximized state.
892897
pub fn is_maximized(&self) -> crate::Result<bool> {
893898
self.window.dispatcher.is_maximized().map_err(Into::into)

tooling/api/src/window.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,31 @@ class WindowManager extends WebviewWindowHandle {
579579
})
580580
}
581581

582+
/**
583+
* Gets the window's current minimized state.
584+
* @example
585+
* ```typescript
586+
* import { appWindow } from '@tauri-apps/api/window';
587+
* const minimized = await appWindow.isMinimized();
588+
* ```
589+
*
590+
* @since 1.3.0
591+
* */
592+
async isMinimized(): Promise<boolean> {
593+
return invokeTauriCommand({
594+
__tauriModule: 'Window',
595+
message: {
596+
cmd: 'manage',
597+
data: {
598+
label: this.label,
599+
cmd: {
600+
type: 'isMinimized'
601+
}
602+
}
603+
}
604+
})
605+
}
606+
582607
/**
583608
* Gets the window's current maximized state.
584609
* @example

0 commit comments

Comments
 (0)