Stable worker naming

This commit is contained in:
Dustin Brett 2025-03-13 12:01:00 -07:00
parent f56c33b74d
commit bafae5b7e8
11 changed files with 36 additions and 58 deletions

View File

@ -25,7 +25,7 @@ export const WALLPAPER_PATHS: Record<
VANTA: () => import("components/system/Desktop/Wallpapers/vantaWaves"), VANTA: () => import("components/system/Desktop/Wallpapers/vantaWaves"),
}; };
export const WALLPAPER_WORKERS: Record<string, (info?: string) => Worker> = { export const WALLPAPER_WORKERS: Record<string, () => Worker> = {
COASTAL_LANDSCAPE: (): Worker => COASTAL_LANDSCAPE: (): Worker =>
new Worker( new Worker(
new URL( new URL(
@ -47,13 +47,13 @@ export const WALLPAPER_WORKERS: Record<string, (info?: string) => Worker> = {
new URL("components/apps/StableDiffusion/sd.worker", import.meta.url), new URL("components/apps/StableDiffusion/sd.worker", import.meta.url),
{ name: "Wallpaper (Stable Diffusion)" } { name: "Wallpaper (Stable Diffusion)" }
), ),
VANTA: (info?: string): Worker => VANTA: (): Worker =>
new Worker( new Worker(
new URL( new URL(
"components/system/Desktop/Wallpapers/vantaWaves/wallpaper.worker", "components/system/Desktop/Wallpapers/vantaWaves/wallpaper.worker",
import.meta.url import.meta.url
), ),
{ name: `Wallpaper (Vanta Waves)${info ? ` [${info}]` : ""}` } { name: "Wallpaper (Vanta Waves)" }
), ),
}; };

View File

@ -63,9 +63,7 @@ const useWallpaper = (
); );
const vantaWireframe = wallpaperImage === "VANTA WIREFRAME"; const vantaWireframe = wallpaperImage === "VANTA WIREFRAME";
const wallpaperWorker = useWorker<void>( const wallpaperWorker = useWorker<void>(
sessionLoaded ? WALLPAPER_WORKERS[wallpaperName] : undefined, sessionLoaded ? WALLPAPER_WORKERS[wallpaperName] : undefined
undefined,
vantaWireframe ? "Wireframe" : ""
); );
const wallpaperTimerRef = useRef(0); const wallpaperTimerRef = useRef(0);
const failedOffscreenContext = useRef(false); const failedOffscreenContext = useRef(false);

View File

@ -22,6 +22,7 @@ import processDirectory from "contexts/process/directory";
import { useSession } from "contexts/session"; import { useSession } from "contexts/session";
import { useProcessesRef } from "hooks/useProcessesRef"; import { useProcessesRef } from "hooks/useProcessesRef";
import { import {
AI_TITLE,
AUDIO_PLAYLIST_EXTENSIONS, AUDIO_PLAYLIST_EXTENSIONS,
CURSOR_FILE_EXTENSIONS, CURSOR_FILE_EXTENSIONS,
DESKTOP_PATH, DESKTOP_PATH,
@ -57,10 +58,6 @@ import {
import { Share } from "components/system/Menu/MenuIcons"; import { Share } from "components/system/Menu/MenuIcons";
import { useWindowAI } from "hooks/useWindowAI"; import { useWindowAI } from "hooks/useWindowAI";
import { getNavButtonByTitle } from "hooks/useGlobalKeyboardShortcuts"; import { getNavButtonByTitle } from "hooks/useGlobalKeyboardShortcuts";
import {
AI_DISPLAY_TITLE,
AI_STAGE,
} from "components/system/Taskbar/AI/constants";
import useTransferDialog, { import useTransferDialog, {
type ObjectReader, type ObjectReader,
} from "components/system/Dialogs/Transfer/useTransferDialog"; } from "components/system/Dialogs/Transfer/useTransferDialog";
@ -552,22 +549,13 @@ const useFileContextMenu = (
if (newTopicButton) { if (newTopicButton) {
newTopicButton?.click(); newTopicButton?.click();
} else { } else {
getNavButtonByTitle(AI_DISPLAY_TITLE)?.click(); getNavButtonByTitle(AI_TITLE)?.click();
} }
}; };
menuItems.unshift(MENU_SEPERATOR, { menuItems.unshift(MENU_SEPERATOR, {
label: `AI (${AI_STAGE})`, action: () => aiCommand("Summarize"),
menu: [ label: "Summarize Text (AI)",
...(aiEnabled || (hasWindowAI && "summarizer" in window.ai)
? [
{
action: () => aiCommand("Summarize"),
label: "Summarize Text",
},
]
: []),
],
}); });
} }

View File

@ -1,11 +1,7 @@
import { importAIChat } from "components/system/Taskbar/functions"; import { importAIChat } from "components/system/Taskbar/functions";
import {
AI_DISPLAY_TITLE,
WINDOW_ID,
} from "components/system/Taskbar/AI/constants";
import { AIIcon } from "components/system/Taskbar/AI/icons"; import { AIIcon } from "components/system/Taskbar/AI/icons";
import StyledAIButton from "components/system/Taskbar/AI/StyledAIButton"; import StyledAIButton from "components/system/Taskbar/AI/StyledAIButton";
import { DIV_BUTTON_PROPS } from "utils/constants"; import { AI_TITLE, AI_WINDOW_ID, DIV_BUTTON_PROPS } from "utils/constants";
import { label } from "utils/functions"; import { label } from "utils/functions";
import useTaskbarContextMenu from "components/system/Taskbar/useTaskbarContextMenu"; import useTaskbarContextMenu from "components/system/Taskbar/useTaskbarContextMenu";
import { useSession } from "contexts/session"; import { useSession } from "contexts/session";
@ -24,10 +20,10 @@ const AIButton: FC<AIButtonProps> = ({ aiVisible, toggleAI }) => {
<StyledAIButton <StyledAIButton
onClick={() => { onClick={() => {
toggleAI(); toggleAI();
if (aiVisible) removeFromStack(WINDOW_ID); if (aiVisible) removeFromStack(AI_WINDOW_ID);
}} }}
{...DIV_BUTTON_PROPS} {...DIV_BUTTON_PROPS}
{...label(AI_DISPLAY_TITLE)} {...label(AI_TITLE)}
{...useTaskbarContextMenu()} {...useTaskbarContextMenu()}
{...menuPreloadHandler} {...menuPreloadHandler}
> >

View File

@ -22,11 +22,8 @@ import {
} from "components/system/Taskbar/AI/icons"; } from "components/system/Taskbar/AI/icons";
import useAITransition from "components/system/Taskbar/AI/useAITransition"; import useAITransition from "components/system/Taskbar/AI/useAITransition";
import { import {
AI_DISPLAY_TITLE,
AI_TITLE,
AI_WORKER, AI_WORKER,
DEFAULT_CONVO_STYLE, DEFAULT_CONVO_STYLE,
WINDOW_ID,
} from "components/system/Taskbar/AI/constants"; } from "components/system/Taskbar/AI/constants";
import StyledAIChat from "components/system/Taskbar/AI/StyledAIChat"; import StyledAIChat from "components/system/Taskbar/AI/StyledAIChat";
import { CloseIcon } from "components/system/Window/Titlebar/WindowActionIcons"; import { CloseIcon } from "components/system/Window/Titlebar/WindowActionIcons";
@ -38,7 +35,13 @@ import {
label, label,
viewWidth, viewWidth,
} from "utils/functions"; } from "utils/functions";
import { DESKTOP_PATH, PREVENT_SCROLL, SAVE_PATH } from "utils/constants"; import {
AI_TITLE,
AI_WINDOW_ID,
DESKTOP_PATH,
PREVENT_SCROLL,
SAVE_PATH,
} from "utils/constants";
import { import {
type MessageTypes, type MessageTypes,
type ConvoStyles, type ConvoStyles,
@ -168,7 +171,7 @@ const AIChat: FC<AIChatProps> = ({ toggleAI }) => {
useState<HTMLElement | null>(); useState<HTMLElement | null>();
const { removeFromStack, setWallpaper } = useSession(); const { removeFromStack, setWallpaper } = useSession();
const { zIndex, ...focusableProps } = useFocusable( const { zIndex, ...focusableProps } = useFocusable(
WINDOW_ID, AI_WINDOW_ID,
undefined, undefined,
containerElement containerElement
); );
@ -371,13 +374,13 @@ const AIChat: FC<AIChatProps> = ({ toggleAI }) => {
> >
<div className="header"> <div className="header">
<header> <header>
{AI_DISPLAY_TITLE} {AI_TITLE} (beta)
<nav> <nav>
<Button <Button
className="close" className="close"
onClick={() => { onClick={() => {
toggleAI(); toggleAI();
removeFromStack(WINDOW_ID); removeFromStack(AI_WINDOW_ID);
}} }}
{...label("Close")} {...label("Close")}
> >

View File

@ -1,11 +1,5 @@
import { type ConvoStyles } from "components/system/Taskbar/AI/types"; import { type ConvoStyles } from "components/system/Taskbar/AI/types";
export const AI_TITLE = "Talos";
export const AI_STAGE = "alpha";
export const AI_DISPLAY_TITLE = `${AI_TITLE} (${AI_STAGE})`;
export const DEFAULT_CONVO_STYLE: ConvoStyles = "balanced"; export const DEFAULT_CONVO_STYLE: ConvoStyles = "balanced";
export const AI_WORKER = (): Worker => export const AI_WORKER = (): Worker =>
@ -13,5 +7,3 @@ export const AI_WORKER = (): Worker =>
new URL("components/system/Taskbar/AI/ai.worker", import.meta.url), new URL("components/system/Taskbar/AI/ai.worker", import.meta.url),
{ name: "AI" } { name: "AI" }
); );
export const WINDOW_ID = "ai-chat-window";

View File

@ -19,11 +19,6 @@ import { useMenuPreload } from "hooks/useMenuPreload";
type ClockWorkerResponse = LocaleTimeDate | "source"; type ClockWorkerResponse = LocaleTimeDate | "source";
const ClockSourceMap = {
local: "Local",
ntp: "Server",
};
const EASTER_EGG_CLICK_COUNT = 7; const EASTER_EGG_CLICK_COUNT = 7;
const LARGEST_CLOCK_TEXT = "44:44:44 AM"; const LARGEST_CLOCK_TEXT = "44:44:44 AM";
@ -85,8 +80,10 @@ const Clock: FC<ClockProps> = ({
"components/system/Taskbar/Clock/clock.worker", "components/system/Taskbar/Clock/clock.worker",
import.meta.url import.meta.url
), ),
{ name: `Clock (${ClockSourceMap[clockSource]})` } { name: "Clock" }
), ),
// NOTE: Need `clockSource` in the dependency array to ensure the worker is rebuilt
// eslint-disable-next-line react-hooks/exhaustive-deps
[clockSource] [clockSource]
); );
const offScreenClockCanvas = useRef<OffscreenCanvas>(undefined); const offScreenClockCanvas = useRef<OffscreenCanvas>(undefined);

View File

@ -1,5 +1,4 @@
import { useMemo } from "react"; import { useMemo } from "react";
import { AI_TITLE } from "components/system/Taskbar/AI/constants";
import { useMenu } from "contexts/menu"; import { useMenu } from "contexts/menu";
import { import {
type ContextMenuCapture, type ContextMenuCapture,
@ -9,7 +8,7 @@ import { useProcesses } from "contexts/process";
import { useSession } from "contexts/session"; import { useSession } from "contexts/session";
import { useViewport } from "contexts/viewport"; import { useViewport } from "contexts/viewport";
import { useProcessesRef } from "hooks/useProcessesRef"; import { useProcessesRef } from "hooks/useProcessesRef";
import { MENU_SEPERATOR } from "utils/constants"; import { AI_TITLE, MENU_SEPERATOR } from "utils/constants";
import { toggleShowDesktop } from "utils/functions"; import { toggleShowDesktop } from "utils/functions";
import { useWebGPUCheck } from "hooks/useWebGPUCheck"; import { useWebGPUCheck } from "hooks/useWebGPUCheck";
import { useWindowAI } from "hooks/useWindowAI"; import { useWindowAI } from "hooks/useWindowAI";

View File

@ -1,15 +1,14 @@
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
const useWorker = <T>( const useWorker = <T>(
workerInit?: (info?: string) => Worker, workerInit?: () => Worker,
onMessage?: (message: MessageEvent<T>) => void, onMessage?: (message: MessageEvent<T>) => void
workerInfo?: string
): React.RefObject<Worker | undefined> => { ): React.RefObject<Worker | undefined> => {
const worker = useRef<Worker>(undefined); const worker = useRef<Worker>(undefined);
useEffect(() => { useEffect(() => {
if (workerInit && !worker.current) { if (workerInit && !worker.current) {
worker.current = workerInit(workerInfo); worker.current = workerInit();
if (onMessage) { if (onMessage) {
worker.current.addEventListener("message", onMessage, { worker.current.addEventListener("message", onMessage, {
@ -24,7 +23,7 @@ const useWorker = <T>(
worker.current?.terminate(); worker.current?.terminate();
worker.current = undefined; worker.current = undefined;
}; };
}, [onMessage, workerInfo, workerInit]); }, [onMessage, workerInit]);
return worker; return worker;
}; };

View File

@ -211,6 +211,10 @@ export const DESKTOP_PATH = `${HOME}/Desktop`;
export const START_MENU_PATH = `${HOME}/Start Menu`; export const START_MENU_PATH = `${HOME}/Start Menu`;
export const AI_TITLE = "Talos";
export const AI_WINDOW_ID = "ai-chat-window";
export const SYSTEM_SHORTCUT_DIRECTORIES = new Set([DESKTOP_PATH]); export const SYSTEM_SHORTCUT_DIRECTORIES = new Set([DESKTOP_PATH]);
export const TRANSITIONS_IN_MILLISECONDS = { export const TRANSITIONS_IN_MILLISECONDS = {

View File

@ -37,7 +37,9 @@ const decodeJxl = async (image: Buffer): Promise<Buffer> =>
(await supportsImageType("image/jxl")) (await supportsImageType("image/jxl"))
? image ? image
: new Promise((resolve) => { : new Promise((resolve) => {
const worker = new Worker("System/JXL.js/jxl_dec.js"); const worker = new Worker("System/JXL.js/jxl_dec.js", {
name: "JXL.js",
});
worker.postMessage({ image, jxlSrc: "image.jxl" }); worker.postMessage({ image, jxlSrc: "image.jxl" });
worker.addEventListener("message", (message: JxlDecodeResponse) => { worker.addEventListener("message", (message: JxlDecodeResponse) => {