Sfoglia il codice sorgente

feat(core): add `is_decorated` Window getter

Lucas Nogueira 4 anni fa
parent
commit
f58a2114fb

+ 5 - 0
.changes/api-is-decorated.md

@@ -0,0 +1,5 @@
+---
+"api": patch
+---
+
+Adds `isDecorated` getter on the window API.

+ 7 - 0
.changes/is-decorated.md

@@ -0,0 +1,7 @@
+---
+"tauri": patch
+"tauri-runtime": patch
+"tauri-runtime-wry": patch
+---
+
+Adds `is_decorated` getter on Window.

+ 7 - 0
core/tauri-runtime-wry/src/lib.rs

@@ -399,6 +399,7 @@ enum WindowMessage {
   OuterSize(Sender<PhysicalSize<u32>>),
   IsFullscreen(Sender<bool>),
   IsMaximized(Sender<bool>),
+  IsDecorated(Sender<bool>),
   CurrentMonitor(Sender<Option<MonitorHandle>>),
   PrimaryMonitor(Sender<Option<MonitorHandle>>),
   AvailableMonitors(Sender<Vec<MonitorHandle>>),
@@ -531,6 +532,11 @@ impl Dispatch for WryDispatcher {
     Ok(dispatcher_getter!(self, WindowMessage::IsMaximized))
   }
 
+  /// Gets the window’s current decoration state.
+  fn is_decorated(&self) -> Result<bool> {
+    Ok(dispatcher_getter!(self, WindowMessage::IsDecorated))
+  }
+
   fn current_monitor(&self) -> Result<Option<Monitor>> {
     Ok(
       dispatcher_getter!(self, WindowMessage::CurrentMonitor)
@@ -1133,6 +1139,7 @@ fn handle_event_loop(
               .unwrap(),
             WindowMessage::IsFullscreen(tx) => tx.send(window.fullscreen().is_some()).unwrap(),
             WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
+            WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
             WindowMessage::CurrentMonitor(tx) => tx.send(window.current_monitor()).unwrap(),
             WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(),
             WindowMessage::AvailableMonitors(tx) => {

+ 3 - 0
core/tauri-runtime/src/lib.rs

@@ -207,6 +207,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
   /// Gets the window's current maximized state.
   fn is_maximized(&self) -> crate::Result<bool>;
 
+  /// Gets the window’s current decoration state.
+  fn is_decorated(&self) -> crate::Result<bool>;
+
   /// Returns the monitor on which the window currently resides.
   ///
   /// Returns None if current monitor can't be detected.

+ 2 - 0
core/tauri/src/endpoints/window.rs

@@ -46,6 +46,7 @@ pub enum Cmd {
   OuterSize,
   IsFullscreen,
   IsMaximized,
+  IsDecorated,
   CurrentMonitor,
   PrimaryMonitor,
   AvailableMonitors,
@@ -129,6 +130,7 @@ impl Cmd {
         Self::OuterSize => return Ok(window.outer_size()?.into()),
         Self::IsFullscreen => return Ok(window.is_fullscreen()?.into()),
         Self::IsMaximized => return Ok(window.is_maximized()?.into()),
+        Self::IsDecorated => return Ok(window.is_decorated()?.into()),
         Self::CurrentMonitor => return Ok(window.current_monitor()?.into()),
         Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
         Self::AvailableMonitors => return Ok(window.available_monitors()?.into()),

+ 5 - 0
core/tauri/src/window.rs

@@ -351,6 +351,11 @@ impl<P: Params> Window<P> {
     self.window.dispatcher.is_maximized().map_err(Into::into)
   }
 
+  /// Gets the window’s current decoration state.
+  pub fn is_decorated(&self) -> crate::Result<bool> {
+    self.window.dispatcher.is_decorated().map_err(Into::into)
+  }
+
   /// Returns the monitor on which the window currently resides.
   ///
   /// Returns None if current monitor can't be detected.

+ 10 - 0
tooling/api/src/window.ts

@@ -362,6 +362,16 @@ class WindowManager {
     })
   }
 
+  /** Gets the window's current decorated state. */
+  async isDecorated(): Promise<boolean> {
+    return invokeTauriCommand({
+      __tauriModule: 'Window',
+      message: {
+        cmd: 'isDecorated'
+      }
+    })
+  }
+
   // Setters
 
   /**