fix: sending multiple images at the same time

This commit is contained in:
2025-05-04 10:14:20 +01:00
parent ce8d546447
commit a8d12b5d53
2 changed files with 22 additions and 3 deletions

View File

@ -9,15 +9,26 @@ type ImageViewerProps = {
) => void;
};
// This probably shouldn't live here.
// The request should be made from rust but hey.
// We'll do that later
export const ImageViewer: Component<ImageViewerProps> = (props) => {
// const [latestImage, setLatestImage] = createSignal<string | null>(null);
let sentImage = "";
createEffect(async () => {
// Listen for PNG processing events
const unlisten = listen("png-processed", async (event) => {
console.log("Received processed PNG", event);
const base64Data = event.payload as string;
if (base64Data === sentImage) {
return;
}
sentImage = base64Data;
const appWindow = getCurrentWindow();
appWindow.show();

View File

@ -1,4 +1,4 @@
import { createEffect, Show, type Accessor, type Component } from "solid-js";
import { createEffect, type Accessor, type Component } from "solid-js";
import { base, type sendImage } from "../../network";
import { useSearchImageContext } from "../../contexts/SearchImageContext";
@ -16,6 +16,8 @@ type EventData = "in-progress" | "complete";
export const ImageStatus: Component<ImageStatusProps> = (props) => {
const { onRefetchImages } = useSearchImageContext();
let processing = false;
const onEvent = (e: MessageEvent<EventData>) => {
console.log("Processing Events: ", e.data);
@ -30,6 +32,8 @@ export const ImageStatus: Component<ImageStatusProps> = (props) => {
Status: e.data,
});
processing = false;
return;
}
@ -43,10 +47,14 @@ export const ImageStatus: Component<ImageStatusProps> = (props) => {
return;
}
if (processing) {
return;
}
processing = true;
const eventSourceUrl = `${base}/image-events/${image.ID}`;
const eventSource = new EventSource(eventSourceUrl);
console.log("URL: ", eventSourceUrl);
eventSource.addEventListener("data", onEvent);