Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48a7a78

Browse files
authored
fix(api): fix dpi types serialization (tauri-apps#9376)
* fix(api): fix dpi types serialization closes tauri-apps#9370 * Update api-position-size-args.md * lint * setMinSize and setMaxSize * Update api-position-size-args.md
1 parent 1d39876 commit 48a7a78

File tree

7 files changed

+77
-68
lines changed

7 files changed

+77
-68
lines changed

.changes/api-position-size-args.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/api": "patch:bug"
3+
---
4+
5+
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.

core/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/src-tauri/Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/api/src/menu/menu.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ export class Menu extends MenuItemBase {
245245
): Promise<void> {
246246
let atValue = null
247247
if (at) {
248-
atValue = {
249-
type: at instanceof PhysicalPosition ? 'Physical' : 'Logical',
250-
data: at
248+
atValue = {} as Record<string, unknown>
249+
atValue[`${at instanceof PhysicalPosition ? 'Physical' : 'Logical'}`] = {
250+
x: at.x,
251+
y: at.y
251252
}
252253
}
253254
return invoke('plugin:menu|popup', {

tooling/api/src/menu/submenu.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ export class Submenu extends MenuItemBase {
245245
): Promise<void> {
246246
let atValue = null
247247
if (at) {
248-
atValue = {
249-
type: at instanceof PhysicalPosition ? 'Physical' : 'Logical',
250-
data: at
248+
atValue = {} as Record<string, unknown>
249+
atValue[`${at instanceof PhysicalPosition ? 'Physical' : 'Logical'}`] = {
250+
x: at.x,
251+
y: at.y
251252
}
252253
}
253254
return invoke('plugin:menu|popup', {

tooling/api/src/webview.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,15 @@ class Webview {
417417
)
418418
}
419419

420+
const value = {} as Record<string, unknown>
421+
value[`${size.type}`] = {
422+
width: size.width,
423+
height: size.height
424+
}
425+
420426
return invoke('plugin:webview|set_webview_size', {
421427
label: this.label,
422-
value: {
423-
type: size.type,
424-
data: {
425-
width: size.width,
426-
height: size.height
427-
}
428-
}
428+
value
429429
})
430430
}
431431

@@ -452,15 +452,15 @@ class Webview {
452452
)
453453
}
454454

455+
const value = {} as Record<string, unknown>
456+
value[`${position.type}`] = {
457+
x: position.x,
458+
y: position.y
459+
}
460+
455461
return invoke('plugin:webview|set_webview_position', {
456462
label: this.label,
457-
value: {
458-
type: position.type,
459-
data: {
460-
x: position.x,
461-
y: position.y
462-
}
463-
}
463+
value
464464
})
465465
}
466466

tooling/api/src/window.ts

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,15 +1227,15 @@ class Window {
12271227
)
12281228
}
12291229

1230+
const value = {} as Record<string, unknown>
1231+
value[`${size.type}`] = {
1232+
width: size.width,
1233+
height: size.height
1234+
}
1235+
12301236
return invoke('plugin:window|set_size', {
12311237
label: this.label,
1232-
value: {
1233-
type: size.type,
1234-
data: {
1235-
width: size.width,
1236-
height: size.height
1237-
}
1238-
}
1238+
value
12391239
})
12401240
}
12411241

@@ -1259,17 +1259,18 @@ class Window {
12591259
)
12601260
}
12611261

1262+
let value = null as Record<string, unknown> | null
1263+
if (size) {
1264+
value = {}
1265+
value[`${size.type}`] = {
1266+
width: size.width,
1267+
height: size.height
1268+
}
1269+
}
1270+
12621271
return invoke('plugin:window|set_min_size', {
12631272
label: this.label,
1264-
value: size
1265-
? {
1266-
type: size.type,
1267-
data: {
1268-
width: size.width,
1269-
height: size.height
1270-
}
1271-
}
1272-
: null
1273+
value
12731274
})
12741275
}
12751276

@@ -1293,17 +1294,18 @@ class Window {
12931294
)
12941295
}
12951296

1297+
let value = null as Record<string, unknown> | null
1298+
if (size) {
1299+
value = {}
1300+
value[`${size.type}`] = {
1301+
width: size.width,
1302+
height: size.height
1303+
}
1304+
}
1305+
12961306
return invoke('plugin:window|set_max_size', {
12971307
label: this.label,
1298-
value: size
1299-
? {
1300-
type: size.type,
1301-
data: {
1302-
width: size.width,
1303-
height: size.height
1304-
}
1305-
}
1306-
: null
1308+
value
13071309
})
13081310
}
13091311

@@ -1330,15 +1332,15 @@ class Window {
13301332
)
13311333
}
13321334

1335+
const value = {} as Record<string, unknown>
1336+
value[`${position.type}`] = {
1337+
x: position.x,
1338+
y: position.y
1339+
}
1340+
13331341
return invoke('plugin:window|set_position', {
13341342
label: this.label,
1335-
value: {
1336-
type: position.type,
1337-
data: {
1338-
x: position.x,
1339-
y: position.y
1340-
}
1341-
}
1343+
value
13421344
})
13431345
}
13441346

@@ -1516,15 +1518,15 @@ class Window {
15161518
)
15171519
}
15181520

1521+
const value = {} as Record<string, unknown>
1522+
value[`${position.type}`] = {
1523+
x: position.x,
1524+
y: position.y
1525+
}
1526+
15191527
return invoke('plugin:window|set_cursor_position', {
15201528
label: this.label,
1521-
value: {
1522-
type: position.type,
1523-
data: {
1524-
x: position.x,
1525-
y: position.y
1526-
}
1527-
}
1529+
value
15281530
})
15291531
}
15301532

0 commit comments

Comments
 (0)