wip: showing the file name

This commit is contained in:
2025-05-01 15:50:03 +01:00
parent afd2e03234
commit 2eda77827a

View File

@ -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<Awaited<ReturnType<typeof sendImage>>>();
const [file, setFile] = createSignal<File>();
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 :(]
</button>
</Show>
<p>{file()?.name}</p>
<ImageViewer onSendImage={setProcessingImage} />
<ImageStatus
processingImage={processingImage}