From 459c8e1c4e721f24ff0ecfb2d44bc79d833a5088 Mon Sep 17 00:00:00 2001 From: John Costa Date: Fri, 18 Jul 2025 14:50:31 +0100 Subject: [PATCH] chore: more cleaning --- frontend/src/App.tsx | 77 ++----------------------- frontend/src/Entity.tsx | 4 +- frontend/src/Search.tsx | 13 ----- frontend/src/components/ImageViewer.tsx | 44 -------------- frontend/src/front/page.tsx | 2 +- frontend/src/mobile/android.ts | 43 ++++++++++++++ frontend/src/mobile/index.ts | 1 + 7 files changed, 53 insertions(+), 131 deletions(-) delete mode 100644 frontend/src/Search.tsx delete mode 100644 frontend/src/components/ImageViewer.tsx create mode 100644 frontend/src/mobile/android.ts create mode 100644 frontend/src/mobile/index.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0a88f49..3d16f41 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -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 = (props) => { return ( @@ -66,53 +49,10 @@ const WithDock: Component = (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 ( - @@ -120,7 +60,7 @@ export const App = () => { - + @@ -129,12 +69,7 @@ export const App = () => { - { - return ; - }} - /> + } /> ); diff --git a/frontend/src/Entity.tsx b/frontend/src/Entity.tsx index dcb33d3..81a3bef 100644 --- a/frontend/src/Entity.tsx +++ b/frontend/src/Entity.tsx @@ -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 = () => {
- {(imageId) => } + {(imageId) => }
)} diff --git a/frontend/src/Search.tsx b/frontend/src/Search.tsx deleted file mode 100644 index c33899c..0000000 --- a/frontend/src/Search.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { ProcessingImages } from "./notifications/ProcessingImages"; -import { Categories } from "./front"; -import { Recent } from "./Recent"; - -export const Search = () => { - return ( -
- - - -
- ); -}; diff --git a/frontend/src/components/ImageViewer.tsx b/frontend/src/components/ImageViewer.tsx deleted file mode 100644 index bcbdef4..0000000 --- a/frontend/src/components/ImageViewer.tsx +++ /dev/null @@ -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(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; -}; diff --git a/frontend/src/front/page.tsx b/frontend/src/front/page.tsx index bcba27e..ba543e3 100644 --- a/frontend/src/front/page.tsx +++ b/frontend/src/front/page.tsx @@ -1,7 +1,7 @@ import { Categories } from "./gallery"; import { Recent } from "./Recent"; -export const Search = () => { +export const FrontPage = () => { return (
diff --git a/frontend/src/mobile/android.ts b/frontend/src/mobile/android.ts new file mode 100644 index 0000000..43848dd --- /dev/null +++ b/frontend/src/mobile/android.ts @@ -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(); + }; + }); +}; diff --git a/frontend/src/mobile/index.ts b/frontend/src/mobile/index.ts new file mode 100644 index 0000000..5d5f7f6 --- /dev/null +++ b/frontend/src/mobile/index.ts @@ -0,0 +1 @@ +export * from "./android";