chore: more cleaning
This commit is contained in:
@ -1,25 +1,9 @@
|
|||||||
import { A, Navigate, Route, Router, useNavigate } from "@solidjs/router";
|
import { A, Navigate, Route, Router, useNavigate } from "@solidjs/router";
|
||||||
import type { PluginListener } from "@tauri-apps/api/core";
|
import { type Component, type ParentProps } from "solid-js";
|
||||||
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 { Login } from "./Login";
|
import { Login } from "./Login";
|
||||||
import { ProtectedRoute } from "./ProtectedRoute";
|
import { ProtectedRoute } from "./ProtectedRoute";
|
||||||
import { Search } from "./Search";
|
|
||||||
import { Settings } from "./Settings";
|
import { Settings } from "./Settings";
|
||||||
import { ImageViewer } from "./components/ImageViewer";
|
|
||||||
import { SearchImageContextProvider } from "./contexts/SearchImageContext";
|
import { SearchImageContextProvider } from "./contexts/SearchImageContext";
|
||||||
import { sendImageFile } from "./network";
|
|
||||||
import { Image } from "./Image";
|
import { Image } from "./Image";
|
||||||
import { WithEntityDialog } from "./WithEntityDialog";
|
import { WithEntityDialog } from "./WithEntityDialog";
|
||||||
import { Gallery } from "./gallery";
|
import { Gallery } from "./gallery";
|
||||||
@ -30,9 +14,8 @@ import {
|
|||||||
IconSearch,
|
IconSearch,
|
||||||
} from "@tabler/icons-solidjs";
|
} from "@tabler/icons-solidjs";
|
||||||
import { Entity } from "./Entity";
|
import { Entity } from "./Entity";
|
||||||
|
import { FrontPage } from "./front";
|
||||||
const currentPlatform = platform();
|
import { onAndroidMount } from "./mobile";
|
||||||
console.log("Current Platform: ", currentPlatform);
|
|
||||||
|
|
||||||
const AppWrapper: Component<ParentProps> = (props) => {
|
const AppWrapper: Component<ParentProps> = (props) => {
|
||||||
return (
|
return (
|
||||||
@ -66,53 +49,10 @@ const WithDock: Component<ParentProps> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const App = () => {
|
export const App = () => {
|
||||||
createEffect(() => {
|
onAndroidMount();
|
||||||
// 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();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SearchImageContextProvider>
|
<SearchImageContextProvider>
|
||||||
<ImageViewer />
|
|
||||||
<Router>
|
<Router>
|
||||||
<Route path="/" component={AppWrapper}>
|
<Route path="/" component={AppWrapper}>
|
||||||
<Route path="/login" component={Login} />
|
<Route path="/login" component={Login} />
|
||||||
@ -120,7 +60,7 @@ export const App = () => {
|
|||||||
<Route path="/" component={ProtectedRoute}>
|
<Route path="/" component={ProtectedRoute}>
|
||||||
<Route path="/" component={WithDock}>
|
<Route path="/" component={WithDock}>
|
||||||
<Route path="/" component={WithEntityDialog}>
|
<Route path="/" component={WithEntityDialog}>
|
||||||
<Route path="/" component={Search} />
|
<Route path="/" component={FrontPage} />
|
||||||
<Route path="/image/:imageId" component={Image} />
|
<Route path="/image/:imageId" component={Image} />
|
||||||
<Route path="/entity/:entityId" component={Entity} />
|
<Route path="/entity/:entityId" component={Entity} />
|
||||||
<Route path="/gallery/:entity" component={Gallery} />
|
<Route path="/gallery/:entity" component={Gallery} />
|
||||||
@ -129,12 +69,7 @@ export const App = () => {
|
|||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
<Route
|
<Route path="*" component={() => <Navigate href="/" />} />
|
||||||
path="*"
|
|
||||||
component={() => {
|
|
||||||
return <Navigate href="/" />;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Router>
|
</Router>
|
||||||
</SearchImageContextProvider>
|
</SearchImageContextProvider>
|
||||||
);
|
);
|
||||||
|
@ -2,7 +2,7 @@ import { useParams } from "@solidjs/router";
|
|||||||
import { Component, For, Show } from "solid-js";
|
import { Component, For, Show } from "solid-js";
|
||||||
import { ConcreteItemModal } from "./components/item-modal/ItemModal";
|
import { ConcreteItemModal } from "./components/item-modal/ItemModal";
|
||||||
import { useSearchImageContext } from "./contexts/SearchImageContext";
|
import { useSearchImageContext } from "./contexts/SearchImageContext";
|
||||||
import { Image } from "./components/image";
|
import { ImageComponent } from "./components/image";
|
||||||
|
|
||||||
export const Entity: Component = () => {
|
export const Entity: Component = () => {
|
||||||
const params = useParams<{ entityId: string }>();
|
const params = useParams<{ entityId: string }>();
|
||||||
@ -21,7 +21,7 @@ export const Entity: Component = () => {
|
|||||||
<div>
|
<div>
|
||||||
<ConcreteItemModal item={e()} />
|
<ConcreteItemModal item={e()} />
|
||||||
<For each={e().data.Images}>
|
<For each={e().data.Images}>
|
||||||
{(imageId) => <Image ID={imageId} />}
|
{(imageId) => <ImageComponent ID={imageId} />}
|
||||||
</For>
|
</For>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -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>
|
|
||||||
);
|
|
||||||
};
|
|
@ -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;
|
|
||||||
};
|
|
@ -1,7 +1,7 @@
|
|||||||
import { Categories } from "./gallery";
|
import { Categories } from "./gallery";
|
||||||
import { Recent } from "./Recent";
|
import { Recent } from "./Recent";
|
||||||
|
|
||||||
export const Search = () => {
|
export const FrontPage = () => {
|
||||||
return (
|
return (
|
||||||
<main class="container pt-2">
|
<main class="container pt-2">
|
||||||
<Categories />
|
<Categories />
|
||||||
|
43
frontend/src/mobile/android.ts
Normal file
43
frontend/src/mobile/android.ts
Normal 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();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
1
frontend/src/mobile/index.ts
Normal file
1
frontend/src/mobile/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from "./android";
|
Reference in New Issue
Block a user