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

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir
2021-08-02 15:43:31 +02:00
committed by GitHub
parent 807b8625b7
commit 1a51006673
10 changed files with 55 additions and 11 deletions

View File

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

View File

@@ -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 one or more lines are too long

View File

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

View File

@@ -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()?,
}
}
}
}
}
}

View File

@@ -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())

View File

@@ -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({

View File

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

View File

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

View File

@@ -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) {