chore: more cleaning

This commit is contained in:
2025-07-18 14:50:31 +01:00
parent ec4e8b7e2a
commit 459c8e1c4e
7 changed files with 53 additions and 131 deletions

View File

@ -1,25 +1,9 @@
import { A, Navigate, Route, Router, useNavigate } from "@solidjs/router";
import type { PluginListener } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { readFile } from "@tauri-apps/plugin-fs";
import { platform } from "@tauri-apps/plugin-os";
import {
type Component,
type ParentProps,
createEffect,
onCleanup,
} from "solid-js";
import {
type ShareEvent,
listenForShareEvents,
} from "tauri-plugin-sharetarget-api";
import { type Component, type ParentProps } from "solid-js";
import { Login } from "./Login";
import { ProtectedRoute } from "./ProtectedRoute";
import { Search } from "./Search";
import { Settings } from "./Settings";
import { ImageViewer } from "./components/ImageViewer";
import { SearchImageContextProvider } from "./contexts/SearchImageContext";
import { sendImageFile } from "./network";
import { Image } from "./Image";
import { WithEntityDialog } from "./WithEntityDialog";
import { Gallery } from "./gallery";
@ -30,9 +14,8 @@ import {
IconSearch,
} from "@tabler/icons-solidjs";
import { Entity } from "./Entity";
const currentPlatform = platform();
console.log("Current Platform: ", currentPlatform);
import { FrontPage } from "./front";
import { onAndroidMount } from "./mobile";
const AppWrapper: Component<ParentProps> = (props) => {
return (
@ -66,53 +49,10 @@ const WithDock: Component<ParentProps> = (props) => {
};
export const App = () => {
createEffect(() => {
// TODO: Don't use window.location.href
const unlisten = listen("focus-search", () => {
window.location.href = "/";
});
onCleanup(() => {
unlisten.then((fn) => fn());
});
});
createEffect(() => {
if (currentPlatform !== "android") {
return;
}
let listener: PluginListener;
const setupListener = async () => {
console.log("Setting up listener");
listener = await listenForShareEvents(async (intent: ShareEvent) => {
console.log(intent);
const contents = await readFile(intent.stream ?? "").catch(
(error: Error) => {
console.warn("fetching shared content failed:");
throw error;
},
);
const f = new File([contents], intent.name ?? "no-name", {
type: intent.content_type,
});
sendImageFile(f.name, f);
});
};
setupListener();
return () => {
listener?.unregister();
};
});
onAndroidMount();
return (
<SearchImageContextProvider>
<ImageViewer />
<Router>
<Route path="/" component={AppWrapper}>
<Route path="/login" component={Login} />
@ -120,7 +60,7 @@ export const App = () => {
<Route path="/" component={ProtectedRoute}>
<Route path="/" component={WithDock}>
<Route path="/" component={WithEntityDialog}>
<Route path="/" component={Search} />
<Route path="/" component={FrontPage} />
<Route path="/image/:imageId" component={Image} />
<Route path="/entity/:entityId" component={Entity} />
<Route path="/gallery/:entity" component={Gallery} />
@ -129,12 +69,7 @@ export const App = () => {
</Route>
</Route>
</Route>
<Route
path="*"
component={() => {
return <Navigate href="/" />;
}}
/>
<Route path="*" component={() => <Navigate href="/" />} />
</Router>
</SearchImageContextProvider>
);

View File

@ -2,7 +2,7 @@ import { useParams } from "@solidjs/router";
import { Component, For, Show } from "solid-js";
import { ConcreteItemModal } from "./components/item-modal/ItemModal";
import { useSearchImageContext } from "./contexts/SearchImageContext";
import { Image } from "./components/image";
import { ImageComponent } from "./components/image";
export const Entity: Component = () => {
const params = useParams<{ entityId: string }>();
@ -21,7 +21,7 @@ export const Entity: Component = () => {
<div>
<ConcreteItemModal item={e()} />
<For each={e().data.Images}>
{(imageId) => <Image ID={imageId} />}
{(imageId) => <ImageComponent ID={imageId} />}
</For>
</div>
)}

View File

@ -1,13 +0,0 @@
import { ProcessingImages } from "./notifications/ProcessingImages";
import { Categories } from "./front";
import { Recent } from "./Recent";
export const Search = () => {
return (
<main class="container pt-2">
<ProcessingImages />
<Categories />
<Recent />
</main>
);
};

View File

@ -1,44 +0,0 @@
import { listen } from "@tauri-apps/api/event";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { type Component, createEffect } from "solid-js";
import { sendImage } from "../network";
// This probably shouldn't live here.
// The request should be made from rust but hey.
// We'll do that later
export const ImageViewer: Component = () => {
// const [latestImage, setLatestImage] = createSignal<string | null>(null);
let sentImage = "";
createEffect(async () => {
// Listen for PNG processing events
const unlisten = listen("png-processed", async (event) => {
const base64Data = event.payload as string;
if (base64Data === sentImage) {
return;
}
sentImage = base64Data;
const appWindow = getCurrentWindow();
appWindow.show();
appWindow.setFocus();
// setLatestImage(`data:image/png;base64,${base64Data}`);
const result = await sendImage("test-image.png", base64Data);
console.log("DBG: ", result);
});
return () => {
unlisten.then((fn) => fn()); // Cleanup listener
};
});
return null;
};

View File

@ -1,7 +1,7 @@
import { Categories } from "./gallery";
import { Recent } from "./Recent";
export const Search = () => {
export const FrontPage = () => {
return (
<main class="container pt-2">
<Categories />

View File

@ -0,0 +1,43 @@
import { PluginListener } from "@tauri-apps/api/core";
import { readFile } from "@tauri-apps/plugin-fs";
import { createEffect } from "solid-js";
import { listenForShareEvents, ShareEvent } from "tauri-plugin-sharetarget-api";
import { sendImageFile } from "../network";
import { platform } from "@tauri-apps/plugin-os";
const currentPlatform = platform();
export const onAndroidMount = () => {
createEffect(() => {
if (currentPlatform !== "android") {
return;
}
let listener: PluginListener;
const setupListener = async () => {
console.log("Setting up listener");
listener = await listenForShareEvents(async (intent: ShareEvent) => {
console.log(intent);
const contents = await readFile(intent.stream ?? "").catch(
(error: Error) => {
console.warn("fetching shared content failed:");
throw error;
},
);
const f = new File([contents], intent.name ?? "no-name", {
type: intent.content_type,
});
sendImageFile(f.name, f);
});
};
setupListener();
return () => {
listener?.unregister();
};
});
};

View File

@ -0,0 +1 @@
export * from "./android";