Restore drag/drop and file-open event handlers in App.tsx
This commit is contained in:
81
src/App.tsx
81
src/App.tsx
@@ -79,46 +79,6 @@ export default function App() {
|
|||||||
const bodyRef = useRef(body);
|
const bodyRef = useRef(body);
|
||||||
const historySnapshotRef = useRef<HistorySnapshot | null>(null);
|
const historySnapshotRef = useRef<HistorySnapshot | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let unlisten: (() => void) | null = null;
|
|
||||||
getCurrentWindow()
|
|
||||||
.onDragDropEvent(async (event) => {
|
|
||||||
if (event.payload.type !== "drop") return;
|
|
||||||
await handleFilePaths(event.payload.paths ?? []);
|
|
||||||
})
|
|
||||||
.then((cleanup) => {
|
|
||||||
unlisten = cleanup;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Failed to register drag/drop handler", error);
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
if (unlisten) unlisten();
|
|
||||||
};
|
|
||||||
}, [handleFilePaths]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let unlisten: (() => void) | null = null;
|
|
||||||
listen<string[]>("file-opened", async (event) => {
|
|
||||||
await handleFilePaths(event.payload ?? []);
|
|
||||||
})
|
|
||||||
.then((cleanup) => {
|
|
||||||
unlisten = cleanup;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Failed to register file-open listener", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
invoke<string[]>("take_pending_opens")
|
|
||||||
.then((paths) => handleFilePaths(paths ?? []))
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Failed to load pending file opens", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (unlisten) unlisten();
|
|
||||||
};
|
|
||||||
}, [handleFilePaths]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
bodyRef.current = body;
|
bodyRef.current = body;
|
||||||
@@ -336,6 +296,47 @@ export default function App() {
|
|||||||
[createTextFromFile]
|
[createTextFromFile]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let unlisten: (() => void) | null = null;
|
||||||
|
getCurrentWindow()
|
||||||
|
.onDragDropEvent(async (event) => {
|
||||||
|
if (event.payload.type !== "drop") return;
|
||||||
|
await handleFilePaths(event.payload.paths ?? []);
|
||||||
|
})
|
||||||
|
.then((cleanup) => {
|
||||||
|
unlisten = cleanup;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Failed to register drag/drop handler", error);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
if (unlisten) unlisten();
|
||||||
|
};
|
||||||
|
}, [handleFilePaths]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let unlisten: (() => void) | null = null;
|
||||||
|
listen<string[]>("file-opened", async (event) => {
|
||||||
|
await handleFilePaths(event.payload ?? []);
|
||||||
|
})
|
||||||
|
.then((cleanup) => {
|
||||||
|
unlisten = cleanup;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Failed to register file-open listener", error);
|
||||||
|
});
|
||||||
|
|
||||||
|
invoke<string[]>("take_pending_opens")
|
||||||
|
.then((paths) => handleFilePaths(paths ?? []))
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Failed to load pending file opens", error);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (unlisten) unlisten();
|
||||||
|
};
|
||||||
|
}, [handleFilePaths]);
|
||||||
|
|
||||||
const handleOpenText = useCallback(async () => {
|
const handleOpenText = useCallback(async () => {
|
||||||
const baseDir = await appDataDir();
|
const baseDir = await appDataDir();
|
||||||
const path = await open({
|
const path = await open({
|
||||||
|
|||||||
Reference in New Issue
Block a user