Browse Source

fix(core): `data-tauri-drag-region` didn't respect resizable, closes #2314 (#2316)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Amr Bashir 4 years ago
parent
commit
1a51006673

+ 5 - 0
.changes/api-toggle-maximize.md

@@ -0,0 +1,5 @@
+---
+"api": patch
+---
+
+Add `toggleMaximize()` function to the `WebviewWindow` class.

+ 5 - 0
.changes/core-drag-region-resizable.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Fix `data-tauri-drag-region` double-click, will now respect `resizable: false` and won't maximize.

File diff suppressed because it is too large
+ 0 - 0
core/tauri/scripts/bundle.js


+ 1 - 1
core/tauri/scripts/core.js

@@ -205,7 +205,7 @@ if (!String.prototype.startsWith) {
             cmd: 'manage',
             data: {
               cmd: {
-                type: e.detail === 2 ? 'toggleMaximize' : 'startDragging'
+                type: e.detail === 2 ? '__toggleMaximize' : 'startDragging'
               }
             }
           }

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

@@ -80,6 +80,9 @@ pub enum WindowManagerCmd {
   SetSkipTaskbar(bool),
   StartDragging,
   Print,
+  // internals
+  #[serde(rename = "__toggleMaximize")]
+  InternalToggleMaximize,
 }
 
 /// The API descriptor.
@@ -179,6 +182,15 @@ impl Cmd {
           WindowManagerCmd::SetSkipTaskbar(skip) => window.set_skip_taskbar(skip)?,
           WindowManagerCmd::StartDragging => window.start_dragging()?,
           WindowManagerCmd::Print => window.print()?,
+          // internals
+          WindowManagerCmd::InternalToggleMaximize => {
+            if window.is_resizable()? {
+              match window.is_maximized()? {
+                true => window.unmaximize()?,
+                false => window.maximize()?,
+              }
+            }
+          }
         }
       }
     }

+ 1 - 1
docs/usage/guides/visual/window-customization.md

@@ -82,7 +82,7 @@ document
   .addEventListener('click', () => appWindow.minimize())
 document
   .getElementById('titlebar-maximize')
-  .addEventListener('click', async () => await appWindow.isMaximized() ? appWindow.unmaximize() : appWindow.maximize())
+  .addEventListener('click', () => appWindow.toggleMaximize())
 document
   .getElementById('titlebar-close')
   .addEventListener('click', () => appWindow.close())

+ 3 - 2
tooling/api/src/helpers/event.ts

@@ -2,8 +2,9 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-/** @ignore */ /** */
+/** @ignore */
 
+import { WindowLabel } from '../window'
 import { invokeTauriCommand } from './tauri'
 
 /**
@@ -16,7 +17,7 @@ import { invokeTauriCommand } from './tauri'
  */
 async function emit(
   event: string,
-  windowLabel?: string,
+  windowLabel: WindowLabel,
   payload?: string
 ): Promise<void> {
   await invokeTauriCommand({

+ 1 - 1
tooling/api/src/helpers/os-check.ts

@@ -2,7 +2,7 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-/** @ignore */ 
+/** @ignore */
 
 function isLinux(): boolean {
   return navigator.appVersion.includes('Linux')

+ 1 - 1
tooling/api/src/helpers/tauri.ts

@@ -2,7 +2,7 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-/** @ignore */ /** */
+/** @ignore */
 
 import { invoke } from '../tauri'
 

+ 25 - 4
tooling/api/src/window.ts

@@ -219,17 +219,18 @@ function getAll(): WebviewWindow[] {
 /** @ignore */
 // events that are emitted right here instead of by the created webview
 const localTauriEvents = ['tauri://created', 'tauri://error']
-
+/** @ignore */
+export type WindowLabel = string | null | undefined
 /**
  * A webview window handle allows emitting and listening to events from the backend that are tied to the window.
  */
 class WebviewWindowHandle {
   /** Window label. */
-  label: string | null
+  label: WindowLabel
   /** Local event listeners. */
   listeners: { [key: string]: Array<EventCallback<any>> }
 
-  constructor(label: string | null) {
+  constructor(label: WindowLabel) {
     this.label = label
     // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
     this.listeners = Object.create(null)
@@ -625,6 +626,26 @@ class WindowManager extends WebviewWindowHandle {
     })
   }
 
+  /**
+   * Toggles the window maximized state.
+   *
+   * @returns A promise indicating the success or failure of the operation.
+   */
+  async toggleMaximize(): Promise<void> {
+    return invokeTauriCommand({
+      __tauriModule: 'Window',
+      message: {
+        cmd: 'manage',
+        data: {
+          label: this.label,
+          cmd: {
+            type: 'toggleMaximize'
+          }
+        }
+      }
+    })
+  }
+
   /**
    * Minimizes the window.
    *
@@ -1071,7 +1092,7 @@ class WindowManager extends WebviewWindowHandle {
  * ```
  */
 class WebviewWindow extends WindowManager {
-  constructor(label: string | null, options: WindowOptions = {}) {
+  constructor(label: WindowLabel, options: WindowOptions = {}) {
     super(label)
     // @ts-expect-error
     if (!options?.skip) {

Some files were not shown because too many files changed in this diff