Skip to content

Commit d32a118

Browse files
jayzcoderqu1ck
authored andcommitted
fix: tauri://file-drop is no longer supported in the new version; use onDragDropEvent.
1 parent 7ec97f8 commit d32a118

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/components/modals/servermodals.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ const ServerModals = React.forwardRef<ModalCallbacks, ServerModalsProps>(functio
105105

106106
useEffect(() => {
107107
if (TAURI) {
108-
const listenResult = appWindow.listen<string[]>("tauri://file-drop", (event) => {
109-
const files = event.payload.filter((path) => path.toLowerCase().endsWith(".torrent"));
110-
if (files.length > 0) enqueue(files);
108+
const dropResult = appWindow.onDragDropEvent((event) => {
109+
if (event.payload.type === "drop") {
110+
const files = event.payload.paths.filter((path) => path.toLowerCase().endsWith(".torrent"));
111+
if (files.length > 0) enqueue(files);
112+
}
111113
});
112-
113-
return () => { void listenResult.then((unlisten) => { unlisten(); }); };
114+
return () => { void dropResult.then((unlisten) => { unlisten(); }); };
114115
} else {
115116
document.ondragover = (e) => { e.preventDefault(); };
116117
document.ondrop = (event) => {

src/taurishim.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import type { EventCallback } from "@tauri-apps/api/event";
2020
import type { CloseRequestedEvent, PhysicalPosition, PhysicalSize } from "@tauri-apps/api/window";
21+
import type { DragDropEvent } from "@tauri-apps/api/webview";
2122

2223
export const TAURI = Object.prototype.hasOwnProperty.call(window, "__TAURI__");
2324
const realAppWindow = TAURI ? (await import(/* webpackMode: "lazy-once" */ "@tauri-apps/api/window")).getCurrentWindow() : undefined;
@@ -36,7 +37,8 @@ export const appWindow = {
3637
listen: async <T>(event: string, handler: EventCallback<T>) =>
3738
await realAppWindow?.listen(event, handler) ?? (() => { }),
3839
once: async <T>(event: string, handler: EventCallback<T>) => await realAppWindow?.once(event, handler),
39-
40+
onDragDropEvent: async (handler: EventCallback<DragDropEvent>) =>
41+
await realAppWindow?.onDragDropEvent(handler) ?? (() => { }),
4042
onCloseRequested: async (handler: (event: CloseRequestedEvent) => void | Promise<void>) =>
4143
await realAppWindow?.onCloseRequested(handler),
4244
onFocusChanged: async (handler: EventCallback<boolean>) =>

0 commit comments

Comments
 (0)