Skip to content

Commit 6f41a27

Browse files
fix(api.js): fix Monitor initialization, closes #4672 (#5314)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 1377f8e commit 6f41a27

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": "patch"
3+
---
4+
5+
Initialize `Monitor` instances with the correct classes for `position` and `size` fields instead of plain object.

core/tauri/scripts/bundle.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.

tooling/api/src/window.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,17 @@ interface WindowOptions {
20352035
theme?: Theme
20362036
}
20372037

2038+
function mapMonitor(m: Monitor | null): Monitor | null {
2039+
return m === null
2040+
? null
2041+
: {
2042+
name: m.name,
2043+
scaleFactor: m.scaleFactor,
2044+
position: new PhysicalPosition(m.position.x, m.position.y),
2045+
size: new PhysicalSize(m.size.width, m.size.height)
2046+
}
2047+
}
2048+
20382049
/**
20392050
* Returns the monitor on which the window currently resides.
20402051
* Returns `null` if current monitor can't be detected.
@@ -2047,7 +2058,7 @@ interface WindowOptions {
20472058
* @since 1.0.0
20482059
*/
20492060
async function currentMonitor(): Promise<Monitor | null> {
2050-
return invokeTauriCommand({
2061+
return invokeTauriCommand<Monitor | null>({
20512062
__tauriModule: 'Window',
20522063
message: {
20532064
cmd: 'manage',
@@ -2057,7 +2068,7 @@ async function currentMonitor(): Promise<Monitor | null> {
20572068
}
20582069
}
20592070
}
2060-
})
2071+
}).then(mapMonitor)
20612072
}
20622073

20632074
/**
@@ -2072,7 +2083,7 @@ async function currentMonitor(): Promise<Monitor | null> {
20722083
* @since 1.0.0
20732084
*/
20742085
async function primaryMonitor(): Promise<Monitor | null> {
2075-
return invokeTauriCommand({
2086+
return invokeTauriCommand<Monitor | null>({
20762087
__tauriModule: 'Window',
20772088
message: {
20782089
cmd: 'manage',
@@ -2082,7 +2093,7 @@ async function primaryMonitor(): Promise<Monitor | null> {
20822093
}
20832094
}
20842095
}
2085-
})
2096+
}).then(mapMonitor)
20862097
}
20872098

20882099
/**
@@ -2096,7 +2107,7 @@ async function primaryMonitor(): Promise<Monitor | null> {
20962107
* @since 1.0.0
20972108
*/
20982109
async function availableMonitors(): Promise<Monitor[]> {
2099-
return invokeTauriCommand({
2110+
return invokeTauriCommand<Monitor[]>({
21002111
__tauriModule: 'Window',
21012112
message: {
21022113
cmd: 'manage',
@@ -2106,7 +2117,7 @@ async function availableMonitors(): Promise<Monitor[]> {
21062117
}
21072118
}
21082119
}
2109-
})
2120+
}).then((ms) => ms.map(mapMonitor) as Monitor[])
21102121
}
21112122

21122123
export {

0 commit comments

Comments
 (0)