浏览代码

Fix file-drop event payload (#8204)

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
i-c-b 1 年之前
父节点
当前提交
b7add750ef
共有 3 个文件被更改,包括 31 次插入6 次删除
  1. 5 0
      .changes/fix-file-drop-event-payload.md
  2. 0 0
      core/tauri/scripts/bundle.global.js
  3. 26 6
      tooling/api/src/window.ts

+ 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.

文件差异内容过多而无法显示
+ 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

部分文件因为文件数量过多而无法显示