fix(api.js): fix Monitor initialization, closes #4672 (#5314)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir 2022-09-30 19:39:51 +02:00 committed by GitHub
parent 1377f8e13b
commit 6f41a27124
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
"api": "patch"
---
Initialize `Monitor` instances with the correct classes for `position` and `size` fields instead of plain object.

File diff suppressed because one or more lines are too long

View File

@ -2035,6 +2035,17 @@ interface WindowOptions {
theme?: Theme
}
function mapMonitor(m: Monitor | null): Monitor | null {
return m === null
? null
: {
name: m.name,
scaleFactor: m.scaleFactor,
position: new PhysicalPosition(m.position.x, m.position.y),
size: new PhysicalSize(m.size.width, m.size.height)
}
}
/**
* Returns the monitor on which the window currently resides.
* Returns `null` if current monitor can't be detected.
@ -2047,7 +2058,7 @@ interface WindowOptions {
* @since 1.0.0
*/
async function currentMonitor(): Promise<Monitor | null> {
return invokeTauriCommand({
return invokeTauriCommand<Monitor | null>({
__tauriModule: 'Window',
message: {
cmd: 'manage',
@ -2057,7 +2068,7 @@ async function currentMonitor(): Promise<Monitor | null> {
}
}
}
})
}).then(mapMonitor)
}
/**
@ -2072,7 +2083,7 @@ async function currentMonitor(): Promise<Monitor | null> {
* @since 1.0.0
*/
async function primaryMonitor(): Promise<Monitor | null> {
return invokeTauriCommand({
return invokeTauriCommand<Monitor | null>({
__tauriModule: 'Window',
message: {
cmd: 'manage',
@ -2082,7 +2093,7 @@ async function primaryMonitor(): Promise<Monitor | null> {
}
}
}
})
}).then(mapMonitor)
}
/**
@ -2096,7 +2107,7 @@ async function primaryMonitor(): Promise<Monitor | null> {
* @since 1.0.0
*/
async function availableMonitors(): Promise<Monitor[]> {
return invokeTauriCommand({
return invokeTauriCommand<Monitor[]>({
__tauriModule: 'Window',
message: {
cmd: 'manage',
@ -2106,7 +2117,7 @@ async function availableMonitors(): Promise<Monitor[]> {
}
}
}
})
}).then((ms) => ms.map(mapMonitor) as Monitor[])
}
export {