Skip to content

Commit

Permalink
fix(core): data-tauri-drag-region didn't respect resizable, closes #…
Browse files Browse the repository at this point in the history
…2314 (#2316)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
amrbashir and lucasfernog committed Aug 2, 2021
1 parent 807b862 commit 1a51006
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changes/api-toggle-maximize.md
@@ -0,0 +1,5 @@
---
"api": patch
---

Add `toggleMaximize()` function to the `WebviewWindow` class.
5 changes: 5 additions & 0 deletions .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.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/tauri/scripts/core.js
Expand Up @@ -205,7 +205,7 @@ if (!String.prototype.startsWith) {
cmd: 'manage',
data: {
cmd: {
type: e.detail === 2 ? 'toggleMaximize' : 'startDragging'
type: e.detail === 2 ? '__toggleMaximize' : 'startDragging'
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions core/tauri/src/endpoints/window.rs
Expand Up @@ -80,6 +80,9 @@ pub enum WindowManagerCmd {
SetSkipTaskbar(bool),
StartDragging,
Print,
// internals
#[serde(rename = "__toggleMaximize")]
InternalToggleMaximize,
}

/// The API descriptor.
Expand Down Expand Up @@ -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()?,
}
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/guides/visual/window-customization.md
Expand Up @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions tooling/api/src/helpers/event.ts
Expand Up @@ -2,8 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

/** @ignore */ /** */
/** @ignore */

import { WindowLabel } from '../window'
import { invokeTauriCommand } from './tauri'

/**
Expand All @@ -16,7 +17,7 @@ import { invokeTauriCommand } from './tauri'
*/
async function emit(
event: string,
windowLabel?: string,
windowLabel: WindowLabel,
payload?: string
): Promise<void> {
await invokeTauriCommand({
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/helpers/os-check.ts
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

/** @ignore */
/** @ignore */

function isLinux(): boolean {
return navigator.appVersion.includes('Linux')
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/helpers/tauri.ts
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

/** @ignore */ /** */
/** @ignore */

import { invoke } from '../tauri'

Expand Down
29 changes: 25 additions & 4 deletions tooling/api/src/window.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1a51006

Please sign in to comment.