From 8f32fd58cafe677c07d9ed9fff84f6e255156d37 Mon Sep 17 00:00:00 2001
From: darkuss <darkussdelta@gmail.com>
Date: Sat, 22 Aug 2026 01:58:37 +0200
Subject: holy shit i'm finally done

---
 src/desktop/index.tsx | 123 ++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 90 insertions(+), 33 deletions(-)

(limited to 'src/desktop/index.tsx')

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&#10;
-                &#10;
-                Tracklist:&#10;
-                  1.  Internet Exploder&#10;
-                  2.  Netpunk (feat. Kasane Teto)&#10;
-                  3.  Free Download&#10;
-                  4.  I am not a Robot&#10;
-                  5.  Content&#10;
-                  6.  Keygen&#10;
-                  7.  Base64&#10;
-                  8.  Readme (feat. Kasane Teto)&#10;
-                  9.  Symlink&#10;
-                  10. Memory&#10;
-
-                  An album about borrowing software forever.&#10;
-
-                  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... &#10;
-                  </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>
 }
-- 
cgit v1.2.3

