mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
5
.changes/api-toggle-maximize.md
Normal file
5
.changes/api-toggle-maximize.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"api": patch
|
||||
---
|
||||
|
||||
Add `toggleMaximize()` function to the `WebviewWindow` class.
|
||||
5
.changes/core-drag-region-resizable.md
Normal file
5
.changes/core-drag-region-resizable.md
Normal 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
@@ -205,7 +205,7 @@ if (!String.prototype.startsWith) {
|
||||
cmd: 'manage',
|
||||
data: {
|
||||
cmd: {
|
||||
type: e.detail === 2 ? 'toggleMaximize' : 'startDragging'
|
||||
type: e.detail === 2 ? '__toggleMaximize' : 'startDragging'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()?,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/** @ignore */
|
||||
/** @ignore */
|
||||
|
||||
function isLinux(): boolean {
|
||||
return navigator.appVersion.includes('Linux')
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/** @ignore */ /** */
|
||||
/** @ignore */
|
||||
|
||||
import { invoke } from '../tauri'
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user