From 8f32fd58cafe677c07d9ed9fff84f6e255156d37 Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 22 Aug 2026 01:58:37 +0200 Subject: holy shit i'm finally done --- src/desktop/link.tsx | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/desktop/link.tsx (limited to 'src/desktop/link.tsx') diff --git a/src/desktop/link.tsx b/src/desktop/link.tsx new file mode 100644 index 0000000..6b31b9e --- /dev/null +++ b/src/desktop/link.tsx @@ -0,0 +1,62 @@ +import { useCallback } from "preact/hooks" +import { getTaskId, taskManager } from "."; +import { signal } from "@preact/signals"; +import { Address } from "$/apps/source"; +import { APP_REGISTRY } from "$/apps"; +import { ComponentChildren } from "preact"; + +export function Link(props: Link.Props) { + const onClick = useCallback((e: MouseEvent) => { + if (props.external) { + return + } + let app = APP_REGISTRY[props.type]; + if (app === undefined) { + console.error(`couldn't find app for file of type "${props.type}"`) + return + } + + taskManager.add({ + app, + source: signal({ + type: props.type, + link: new URL(props.link), + pixelated: props.pixelated + } as Address), + window: { + minimized: signal(false), + maximized: signal(false), + height: props.type === "link" ? "40vh" : undefined, + width: props.type === "link" ? "40vw" : undefined, + z: signal(taskManager.tasks.value.value.length) + }, + title: signal(undefined), + id: getTaskId(), + contentReady: signal(false), + sizingFinished: signal(false) + }) + e.preventDefault(); + }, []) + + const content = + { props.children ?? props.link } + + + if (props.type === "image" || props.type === "video" || props.type === "audio" || props.block) { + return + } else { + return content + } +} + +namespace Link { + export type Props = { + link: string, + alt?: string, + type: "video" | "image" | "link" | "audio", + block?: boolean, + pixelated?: boolean, + external?: boolean, + children?: ComponentChildren + } +} -- cgit v1.2.3