mirror of https://github.com/tauri-apps/tauri
feat(api): validate window API `size` and `location` arguments (#1846)
* feat(api): validate window API `size` and `location` arguments * fmt
This commit is contained in:
parent
c1f8e11342
commit
7616e6cc7b
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"api": patch
|
||||
---
|
||||
|
||||
Validate arguments on the window `setLocation`, `setSize`, `setMinSize` and `setMaxSize` API.
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -511,11 +511,21 @@ export class WindowManager {
|
|||
|
||||
/**
|
||||
* Resizes the window.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appWindow, LogicalSize } from '@tauri-apps/api/window'
|
||||
* await appWindow.setSize(new LogicalSize(600, 500))
|
||||
* ```
|
||||
*
|
||||
* @param size The logical or physical size.
|
||||
* @returns A promise indicating the success or failure of the operation.
|
||||
*/
|
||||
async setSize(size: LogicalSize | PhysicalSize): Promise<void> {
|
||||
if (!size || (size.type !== 'Logical' && size.type !== 'Physical')) {
|
||||
throw new Error(
|
||||
'the `size` argument must be either a LogicalSize or a PhysicalSize instance'
|
||||
)
|
||||
}
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: 'Window',
|
||||
message: {
|
||||
|
@ -532,7 +542,12 @@ export class WindowManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the window min size.
|
||||
* Sets the window min size. If the `size` argument is not provided, the min size is unset.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appWindow, PhysicalSize } from '@tauri-apps/api/window'
|
||||
* await appWindow.setMinSize(new PhysicalSize(600, 500))
|
||||
* ```
|
||||
*
|
||||
* @param size The logical or physical size.
|
||||
* @returns A promise indicating the success or failure of the operation.
|
||||
|
@ -540,6 +555,11 @@ export class WindowManager {
|
|||
async setMinSize(
|
||||
size: LogicalSize | PhysicalSize | undefined
|
||||
): Promise<void> {
|
||||
if (size && size.type !== 'Logical' && size.type !== 'Physical') {
|
||||
throw new Error(
|
||||
'the `size` argument must be either a LogicalSize or a PhysicalSize instance'
|
||||
)
|
||||
}
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: 'Window',
|
||||
message: {
|
||||
|
@ -558,7 +578,12 @@ export class WindowManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the window max size.
|
||||
* Sets the window max size. If the `size` argument is undefined, the max size is unset.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appWindow, LogicalSize } from '@tauri-apps/api/window'
|
||||
* await appWindow.setMaxSize(new LogicalSize(600, 500))
|
||||
* ```
|
||||
*
|
||||
* @param size The logical or physical size.
|
||||
* @returns A promise indicating the success or failure of the operation.
|
||||
|
@ -566,6 +591,11 @@ export class WindowManager {
|
|||
async setMaxSize(
|
||||
size: LogicalSize | PhysicalSize | undefined
|
||||
): Promise<void> {
|
||||
if (size && size.type !== 'Logical' && size.type !== 'Physical') {
|
||||
throw new Error(
|
||||
'the `size` argument must be either a LogicalSize or a PhysicalSize instance'
|
||||
)
|
||||
}
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: 'Window',
|
||||
message: {
|
||||
|
@ -585,6 +615,11 @@ export class WindowManager {
|
|||
|
||||
/**
|
||||
* Sets the window position.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appWindow, LogicalPosition } from '@tauri-apps/api/window'
|
||||
* await appWindow.setPosition(new LogicalPosition(600, 500))
|
||||
* ```
|
||||
*
|
||||
* @param position The new position, in logical or physical pixels.
|
||||
* @returns A promise indicating the success or failure of the operation.
|
||||
|
@ -592,6 +627,14 @@ export class WindowManager {
|
|||
async setPosition(
|
||||
position: LogicalPosition | PhysicalPosition
|
||||
): Promise<void> {
|
||||
if (
|
||||
!position ||
|
||||
(position.type !== 'Logical' && position.type !== 'Physical')
|
||||
) {
|
||||
throw new Error(
|
||||
'the `position` argument must be either a LogicalPosition or a PhysicalPosition instance'
|
||||
)
|
||||
}
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: 'Window',
|
||||
message: {
|
||||
|
@ -750,6 +793,4 @@ export {
|
|||
availableMonitors
|
||||
}
|
||||
|
||||
export type {
|
||||
Monitor
|
||||
}
|
||||
export type { Monitor }
|
||||
|
|
Loading…
Reference in New Issue