Skip to content

Commit

Permalink
fix(api): fix dpi types serialization (#9376)
Browse files Browse the repository at this point in the history
* fix(api): fix dpi types serialization

closes #9370

* Update api-position-size-args.md

* lint

* setMinSize and setMaxSize

* Update api-position-size-args.md
  • Loading branch information
amrbashir authored Apr 15, 2024
1 parent 1d39876 commit 48a7a78
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .changes/api-position-size-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": "patch:bug"
---

Fix `Window/Webview/WebviewWindow.setSize`, `Window/Webview/WebviewWindow.setPostion`, `Window/WebviewWindow.setMinSize`, `Window/WebviewWindow.setMaxSize`, `Window/WebviewWindow.setCursorPosition` and `Menu/Submenu.popup` methods failing with invalid args.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tooling/api/src/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ export class Menu extends MenuItemBase {
): Promise<void> {
let atValue = null
if (at) {
atValue = {
type: at instanceof PhysicalPosition ? 'Physical' : 'Logical',
data: at
atValue = {} as Record<string, unknown>
atValue[`${at instanceof PhysicalPosition ? 'Physical' : 'Logical'}`] = {
x: at.x,
y: at.y
}
}
return invoke('plugin:menu|popup', {
Expand Down
7 changes: 4 additions & 3 deletions tooling/api/src/menu/submenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ export class Submenu extends MenuItemBase {
): Promise<void> {
let atValue = null
if (at) {
atValue = {
type: at instanceof PhysicalPosition ? 'Physical' : 'Logical',
data: at
atValue = {} as Record<string, unknown>
atValue[`${at instanceof PhysicalPosition ? 'Physical' : 'Logical'}`] = {
x: at.x,
y: at.y
}
}
return invoke('plugin:menu|popup', {
Expand Down
28 changes: 14 additions & 14 deletions tooling/api/src/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ class Webview {
)
}

const value = {} as Record<string, unknown>
value[`${size.type}`] = {
width: size.width,
height: size.height
}

return invoke('plugin:webview|set_webview_size', {
label: this.label,
value: {
type: size.type,
data: {
width: size.width,
height: size.height
}
}
value
})
}

Expand All @@ -452,15 +452,15 @@ class Webview {
)
}

const value = {} as Record<string, unknown>
value[`${position.type}`] = {
x: position.x,
y: position.y
}

return invoke('plugin:webview|set_webview_position', {
label: this.label,
value: {
type: position.type,
data: {
x: position.x,
y: position.y
}
}
value
})
}

Expand Down
80 changes: 41 additions & 39 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,15 +1227,15 @@ class Window {
)
}

const value = {} as Record<string, unknown>
value[`${size.type}`] = {
width: size.width,
height: size.height
}

return invoke('plugin:window|set_size', {
label: this.label,
value: {
type: size.type,
data: {
width: size.width,
height: size.height
}
}
value
})
}

Expand All @@ -1259,17 +1259,18 @@ class Window {
)
}

let value = null as Record<string, unknown> | null
if (size) {
value = {}
value[`${size.type}`] = {
width: size.width,
height: size.height
}
}

return invoke('plugin:window|set_min_size', {
label: this.label,
value: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
value
})
}

Expand All @@ -1293,17 +1294,18 @@ class Window {
)
}

let value = null as Record<string, unknown> | null
if (size) {
value = {}
value[`${size.type}`] = {
width: size.width,
height: size.height
}
}

return invoke('plugin:window|set_max_size', {
label: this.label,
value: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
value
})
}

Expand All @@ -1330,15 +1332,15 @@ class Window {
)
}

const value = {} as Record<string, unknown>
value[`${position.type}`] = {
x: position.x,
y: position.y
}

return invoke('plugin:window|set_position', {
label: this.label,
value: {
type: position.type,
data: {
x: position.x,
y: position.y
}
}
value
})
}

Expand Down Expand Up @@ -1516,15 +1518,15 @@ class Window {
)
}

const value = {} as Record<string, unknown>
value[`${position.type}`] = {
x: position.x,
y: position.y
}

return invoke('plugin:window|set_cursor_position', {
label: this.label,
value: {
type: position.type,
data: {
x: position.x,
y: position.y
}
}
value
})
}

Expand Down

0 comments on commit 48a7a78

Please sign in to comment.