Browse Source

Fix file-drop event payload (#8204)

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
i-c-b 1 year ago
parent
commit
b7add750ef

+ 5 - 0
.changes/fix-file-drop-event-payload.md

@@ -0,0 +1,5 @@
+---
+"@tauri-apps/api": 'patch:enhance'
+---
+
+Added `position` field to the `FileDropEvent` payload.

File diff suppressed because it is too large
+ 0 - 0
core/tauri/scripts/bundle.global.js


+ 26 - 6
tooling/api/src/window.ts

@@ -57,10 +57,15 @@ interface ScaleFactorChanged {
   size: PhysicalSize
 }
 
+interface FileDropPayload {
+  paths: string[]
+  position: PhysicalPosition
+}
+
 /** The file drop event types. */
 type FileDropEvent =
-  | { type: 'hover'; paths: string[] }
-  | { type: 'drop'; paths: string[] }
+  | ({ type: 'hover' } & FileDropPayload)
+  | ({ type: 'drop' } & FileDropPayload)
   | { type: 'cancel' }
 
 /**
@@ -1730,17 +1735,31 @@ class Window {
   async onFileDropEvent(
     handler: EventCallback<FileDropEvent>
   ): Promise<UnlistenFn> {
-    const unlistenFileDrop = await this.listen<string[]>(
+    const unlistenFileDrop = await this.listen<FileDropPayload>(
       TauriEvent.WINDOW_FILE_DROP,
       (event) => {
-        handler({ ...event, payload: { type: 'drop', paths: event.payload } })
+        handler({
+          ...event,
+          payload: {
+            type: 'drop',
+            paths: event.payload.paths,
+            position: mapPhysicalPosition(event.payload.position)
+          }
+        })
       }
     )
 
-    const unlistenFileHover = await this.listen<string[]>(
+    const unlistenFileHover = await this.listen<FileDropPayload>(
       TauriEvent.WINDOW_FILE_DROP_HOVER,
       (event) => {
-        handler({ ...event, payload: { type: 'hover', paths: event.payload } })
+        handler({
+          ...event,
+          payload: {
+            type: 'hover',
+            paths: event.payload.paths,
+            position: mapPhysicalPosition(event.payload.position)
+          }
+        })
       }
     )
 
@@ -2182,6 +2201,7 @@ export type {
   Theme,
   TitleBarStyle,
   ScaleFactorChanged,
+  FileDropPayload,
   FileDropEvent,
   WindowOptions,
   Color

Some files were not shown because too many files changed in this diff