Эх сурвалжийг харах

fix(api): construct correct object for onResized and onMoved, closes #6507 (#6509)

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Amr Bashir 2 жил өмнө
parent
commit
0b46637eba

+ 5 - 0
.changes/api-on-resized-on-moved.md

@@ -0,0 +1,5 @@
+---
+'api': 'patch'
+---
+
+Return correct type for `event.payload ` in `onResized` and `onMoved` window event handlers.

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
core/tauri/scripts/bundle.global.js


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
tooling/api/docs/js-api.json


+ 18 - 4
tooling/api/src/window.ts

@@ -1672,7 +1672,10 @@ class WindowManager extends WebviewWindowHandle {
    * @since 1.0.2
    */
   async onResized(handler: EventCallback<PhysicalSize>): Promise<UnlistenFn> {
-    return this.listen<PhysicalSize>(TauriEvent.WINDOW_RESIZED, handler)
+    return this.listen<PhysicalSize>(TauriEvent.WINDOW_RESIZED, (e) => {
+      e.payload = mapPhysicalSize(e.payload)
+      handler(e)
+    })
   }
 
   /**
@@ -1695,7 +1698,10 @@ class WindowManager extends WebviewWindowHandle {
    * @since 1.0.2
    */
   async onMoved(handler: EventCallback<PhysicalPosition>): Promise<UnlistenFn> {
-    return this.listen<PhysicalPosition>(TauriEvent.WINDOW_MOVED, handler)
+    return this.listen<PhysicalPosition>(TauriEvent.WINDOW_MOVED, (e) => {
+      e.payload = mapPhysicalPosition(e.payload)
+      handler(e)
+    })
   }
 
   /**
@@ -2154,11 +2160,19 @@ function mapMonitor(m: Monitor | null): Monitor | 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)
+        position: mapPhysicalPosition(m.position),
+        size: mapPhysicalSize(m.size)
       }
 }
 
+function mapPhysicalPosition(m: PhysicalPosition): PhysicalPosition {
+  return new PhysicalPosition(m.x, m.y)
+}
+
+function mapPhysicalSize(m: PhysicalSize): PhysicalSize {
+  return new PhysicalSize(m.width, m.height)
+}
+
 /**
  * Returns the monitor on which the window currently resides.
  * Returns `null` if current monitor can't be detected.

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно