diff options
Diffstat (limited to 'src/desktop/index.tsx')
| -rw-r--r-- | src/desktop/index.tsx | 123 |
1 files changed, 90 insertions, 33 deletions
diff --git a/src/desktop/index.tsx b/src/desktop/index.tsx index 021d3a0..b47422d 100644 --- a/src/desktop/index.tsx +++ b/src/desktop/index.tsx @@ -1,43 +1,100 @@ +import "$/apps" // registers all of the apps; import { useRef } from "preact/hooks" -import { Edit } from "./apps/edit" import { Window } from "./window" -import { Music } from "./apps/music"; +import { FILE_REGISTRY } from "./files"; +import { Source } from "$/apps/source"; +import { App } from "$/apps"; +import { createModel, Signal, signal } from "@preact/signals"; +import { MutableValue } from "$/util"; +import { File } from "./file"; +import { StartMenu } from "./start"; + +export type Task = { + app: App, + source: Signal<Source>, + window: { + minimized: Signal<boolean>, + maximized: Signal<boolean> + width?: string | number; + height?: string | number; + position?: { + x?: string | number; + y?: string | number; + }, + z: Signal<number>; + } + title: Signal<string | undefined>, + id: number; + contentReady: Signal<boolean>, + sizingFinished: Signal<boolean> +} + +const TaskManagerModel = createModel(() => { + const tasks: Signal<MutableValue<Task[]>> = signal(new MutableValue([])) + + return { + tasks, + close(currentTask: Task) { + tasks.value = tasks.value.deriveNew(self => { + const idx = self.findIndex(task => { + return currentTask === task + }) + self.splice(idx, 1); + return self + }) + }, + focusWindow(currentTask: Task) { + const t = tasks.value.value; + const currentTaskZ = currentTask.window.z.value; + + for (const task of t) { + if (task === currentTask) { + task.window.z.value = t.length - 1 + } else if (task.window.z.value > currentTaskZ) { + task.window.z.value = task.window.z.value - 1 + } + } + }, + add(task: Task) { + tasks.value = tasks.value.deriveNew(self => { + self.push(task) + return self + }) + } + } +}) +export const taskManager = new TaskManagerModel(); + +let taskCounter = 0; +export function getTaskId(): number { + return taskCounter++; +} export function Desktop() { const ref = useRef(null); + return <div id="desktop" ref={ref}> - <div class="icon_grid"> - <div></div> - <div></div> - <div></div> - <div></div> - <div></div> + <div class="icon_list"> + { FILE_REGISTRY.map(file => <File file={file} />)} </div> - <Window title="README.txt" width="30vw" height={300} x={40} y={40} desktop={ref}> - <Edit> - Fine release by Sunnexo 2026 - - Tracklist: - 1. Internet Exploder - 2. Netpunk (feat. Kasane Teto) - 3. Free Download - 4. I am not a Robot - 5. Content - 6. Keygen - 7. Base64 - 8. Readme (feat. Kasane Teto) - 9. Symlink - 10. Memory - - An album about borrowing software forever. - - A clumsy robot forgets about their girlfriend's anniversary, scrambling to find something to do for the date, eventually concluding they should watch a movie. Of course the movie is in high demand, so the tickets have sold out. Ultimately they resort to piracy, and things spiral out of control... - </Edit> - </Window> - <Window title="Stream Netpunk" desktop={ref}> - <Music /> - </Window> - + { taskManager.tasks.value.value.map(task => { + const App = task.app; + return <Window + key={task.id} + task={task} + desktop={ref} + onFocus={taskManager.focusWindow} + onClose={taskManager.close} + > + <App + title={task.title} + source={task.source} + contentReady={task.contentReady} + sizingFinished={task.sizingFinished} + /> + </Window> + })} + <StartMenu /> <img id="netpunk" src="/assets/netpunk.png" /> </div> } |
