diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 941f199..78a700b 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -8,9 +8,14 @@ import { Settings } from "./Settings"; import { ImageViewer } from "./components/ImageViewer"; import type { sendImage } from "./network"; import { ImageStatus } from "./components/image-status/ImageStatus"; -import { invoke } from "@tauri-apps/api/core"; +import { invoke, type PluginListener } from "@tauri-apps/api/core"; import { SearchImageContextProvider } from "./contexts/SearchImageContext"; import { platform } from "@tauri-apps/plugin-os"; +import { + listenForShareEvents, + type ShareEvent, +} from "tauri-plugin-sharetarget-api"; +import { readFile } from "@tauri-apps/plugin-fs"; const currentPlatform = platform(); @@ -18,6 +23,8 @@ export const App = () => { const [processingImage, setProcessingImage] = createSignal>>(); + const [file, setFile] = createSignal(); + createEffect(() => { // TODO: Don't use window.location.href const unlisten = listen("focus-search", () => { @@ -29,31 +36,34 @@ export const App = () => { }); }); - // createEffect(() => { - // let listener: PluginListener; - // const setupListener = async () => { - // listener = await listenForShareEvents( - // async (intent: ShareEvent) => { - // const contents = await readFile(intent.stream ?? "").catch( - // (error: Error) => { - // console.warn("fetching shared content failed:"); - // throw error; - // }, - // ); - // setFile( - // new File([contents], intent.name ?? "no-name", { - // type: intent.content_type, - // }), - // ); - // setLogs((l) => [...l, intent.uri]); - // }, - // ); - // }; - // setupListener(); - // return () => { - // listener?.unregister(); - // }; - // }); + createEffect(() => { + if (currentPlatform !== "ios" && currentPlatform !== "android") { + return; + } + + let listener: PluginListener; + const setupListener = async () => { + listener = await listenForShareEvents( + async (intent: ShareEvent) => { + const contents = await readFile(intent.stream ?? "").catch( + (error: Error) => { + console.warn("fetching shared content failed:"); + throw error; + }, + ); + setFile( + new File([contents], intent.name ?? "no-name", { + type: intent.content_type, + }), + ); + }, + ); + }; + setupListener(); + return () => { + listener?.unregister(); + }; + }); const onTakeScreenshot = () => { invoke("take_screenshot"); @@ -66,6 +76,7 @@ export const App = () => { Take Screenshot [wayland :(] +

{file()?.name}