Skip to content

Commit f8f35ff

Browse files
committed
(v0.1.4.5-alpha) Optimize: Single App.js + React Component for apps
1. Have ONLY App.js with all the necessary variables so that we do not need to manually add apps to each part. 2. Using React component than Iframes, as they are quite a memory hogger and a can degrade performance.
1 parent 03ad86c commit f8f35ff

File tree

9 files changed

+51
-92
lines changed

9 files changed

+51
-92
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Your PC has been compromised by a group called the "HackClub". Can you regain co
1010
- [X] Windows Design + Desktop Design (Done in v0.1.3... & v0.1.4... respectively)
1111
- [X] Windows start menu does nothing rn. (Done in v0.1.4.4)
1212
- [X] Minimizing window still takes up the zIndex and prevents from using it.(FIXED IN v0.1.3.3-alpha)
13-
- [X] Clicking app on task bar checks if it is focussed or not then: if focussed minimize it, else focus it. (v0.1.3.3-alpha)
13+
- [X] FEAT: Clicking app on task bar checks if it is focussed or not then: if focussed minimize it, else focus it. (v0.1.3.3-alpha)
1414
- [X] Bug: Closing all apps still makes one of them active (visual) (FIXED: v0.1.3.4-alpha)
15-
- [X] Windows Lag when moving (FIXED in v0.1.3.5).
16-
- [X] Draggable component throughout (FIXED in v0.1.3.5).
15+
- [X] BUG: Windows Lag when moving (FIXED in v0.1.3.5).
16+
- [X] ~~Draggable~~ Extendable component throughout the window (FIXED in v0.1.3.5).
1717
- [X] Dynamic Grid (Fixed in v0.1.4.1)
1818
- [X] the text to icon ratio is too big, maybe either increase the size of the icon or decrease the size of the text (do both) (Done in v0.1.4.2)
1919
- [X] Routers for the desktop Apps. (Done in v0.1.4.2)
@@ -24,3 +24,5 @@ Your PC has been compromised by a group called the "HackClub". Can you regain co
2424
- [X] BUG: Closing on fullscreen saves the state. On the opening again it starts in fullscreen. (Fixed in v0.1.4.3(1))
2525
- [ ] QOL: drag the window, even outside the bounding box, or the window keeping padding of like 1rem.
2626
- [ ] BUG: Clicking on the windows icon when the start menu is active causes a jittering effect and doesn't close it.
27+
- [X] OPTIMIZATION: Have ONLY App.js with all the necessary variables so that we do not need to manually add apps to each part. (Done in v0.1.4.5)
28+
- [X] OPTIMIZATION: (TruthEntity) thinks it is better to use React component than Iframes, as they are quite a memory hogger and a can degrade performance. (Done in v0.1.4.5)

src/App.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import './styles/variables.css'
66
import LockScreen from "./routes/lockscreen.jsx";
77
import Desktop from "./routes/desktop.jsx";
88

9-
import DesktopApps from "./DesktopApps.jsx";
10-
119

1210
function App() {
1311
return (
@@ -16,8 +14,6 @@ function App() {
1614
<Routes>
1715
<Route path="/desktop" Component={LockScreen}/>
1816
<Route path="/" Component={Desktop}/>
19-
20-
<Route path="/apps/*" element={<DesktopApps />} />
2117
</Routes>
2218
</div>
2319
</>

src/DesktopApps.jsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/core/WindowManager.jsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@ import { Rnd } from "react-rnd";
33
import "../styles/core/WindowManager.css"
44
import { X, Square, Copy, Minus } from 'lucide-react';
55

6-
export let INITIAL_Z = 1000;
7-
8-
export function getNextZ() {
9-
INITIAL_Z += 1;
10-
return INITIAL_Z;
11-
}
12-
136
export default function AppWindow({
147
title,
15-
src,
8+
AppComponent,
169
imgSrc,
1710
zIndex,
1811
fullscreen = false,
@@ -121,18 +114,7 @@ export default function AppWindow({
121114
</div>
122115
</div>
123116

124-
<iframe
125-
className={"window-obj"}
126-
src={src}
127-
style={{
128-
flex: 1,
129-
border: "none",
130-
width: "100%",
131-
height: "100%",
132-
pointerEvents: isInteracting ? "none" : "auto"
133-
}}
134-
title={title}
135-
/>
117+
< AppComponent />
136118
</div>
137119
</Rnd>
138120
);

src/data/Apps.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
1+
import Chrome from "../apps/chrome.jsx";
2+
import Explorer from "../apps/explorer.jsx";
3+
import Settings from "../apps/settings.jsx";
4+
import VSCode from "../apps/vscode.jsx";
5+
import Terminal from "../apps/terminal.jsx";
6+
import Readme_txt from "../apps/README.txt.jsx";
7+
8+
export let INITIAL_Z = 1000;
9+
10+
export function getNextZ() {
11+
INITIAL_Z += 1;
12+
return INITIAL_Z;
13+
}
14+
115
export const APP_REGISTRY = {
216
explorer: {
317
title: "Explorer",
4-
src: "/?start=/apps/explorer",
18+
component: Explorer,
519
imgSrc: "/assets/icons/Explorer.ico",
620
},
721
vscode: {
822
title: "VS Code",
9-
src: "/?start=/apps/vscode",
23+
component: VSCode,
1024
imgSrc: "/assets/icons/VSCode.svg",
1125
},
1226
settings: {
1327
title: "Settings",
14-
src: "/?start=/apps/settings",
28+
component: Settings,
1529
imgSrc: "/assets/icons/Settings.ico",
1630
},
1731
chrome: {
1832
title: "Chrome",
19-
src: "/?start=/apps/chrome",
33+
component: Chrome,
2034
imgSrc: "/assets/icons/Chrome.ico",
2135
},
2236
terminal: {
2337
title: "Terminal",
24-
src: "/?start=/apps/terminal",
38+
component: Terminal,
2539
imgSrc: "/assets/icons/Terminal.ico",
2640
},
2741

2842
readme_txt: {
2943
title: "README.txt",
30-
src: "/?start=/apps/readme_txt",
44+
component: Readme_txt,
3145
imgSrc: "/assets/icons/Notepad.png",
3246
}
3347
};

src/main.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ import App from './App.jsx'
77

88
import {MemoryRouter} from "react-router-dom";
99

10-
const params = new URLSearchParams(window.location.search);
11-
const startPath = params.get("start") || "/";
12-
1310
createRoot(document.getElementById('root')).render(
1411
<StrictMode>
15-
<MemoryRouter initialEntries={[startPath]}>
12+
<MemoryRouter>
1613
<App/>
1714
</MemoryRouter>
1815
</StrictMode>,

src/routes/desktop.jsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import '../styles/routes/desktop.css';
22
import { Wifi, Volume2, Bell, Search } from 'lucide-react';
3-
import AppWindow, { INITIAL_Z, getNextZ } from '../core/WindowManager.jsx';
43
import {createRef, useRef, useState, useMemo, useEffect} from "react";
5-
import { APP_REGISTRY } from "../data/Apps.js";
4+
import { APP_REGISTRY, INITIAL_Z, getNextZ } from "../data/Apps.js";
5+
6+
import AppWindow from "../core/WindowManager.jsx";
67

78
import Draggable from 'react-draggable';
89
import { motion, AnimatePresence } from "framer-motion";
@@ -11,7 +12,6 @@ function Desktop() {
1112
const [isStartMenuActive, setIsStartMenuActive] = useState(false);
1213

1314
const startMenuRef = useRef(null);
14-
1515
useEffect(() => {
1616
const handleClickOutside = (event) => {
1717
if (isStartMenuActive && startMenuRef.current && !startMenuRef.current.contains(event.target)) {
@@ -35,26 +35,29 @@ function Desktop() {
3535

3636
const [selectedIcon, setSelectedIcon] = useState(null);
3737
const [focussed, setFocussed] = useState(null);
38-
const [apps, setApps] = useState({
39-
explorer: { isOpen: false, minimized: true, fullscreen: false, zIndex: INITIAL_Z, initialX: 0, initialY: 0 },
40-
vscode: { isOpen: false, minimized: true, fullscreen: false, zIndex: INITIAL_Z, initialX: 0, initialY: 0 },
41-
settings: { isOpen: false, minimized: true, fullscreen: false, zIndex: INITIAL_Z, initialX: 0, initialY: 0 },
42-
chrome: { isOpen: false, minimized: true, fullscreen: false, zIndex: INITIAL_Z, initialX: 0, initialY: 0 },
43-
terminal: { isOpen: false, minimized: true, fullscreen: false, zIndex: INITIAL_Z, initialX: 0, initialY: 0 },
44-
readme_txt: { isOpen: false, minimized: true, fullscreen: false, zIndex: INITIAL_Z, initialX: 0, initialY: 0 },
38+
const [apps, setApps] = useState(() => {
39+
return Object.keys(APP_REGISTRY).reduce((acc, key) => {
40+
acc[key] = {
41+
isOpen: false,
42+
minimized: true,
43+
fullscreen: false,
44+
zIndex: INITIAL_Z,
45+
initialX: 0,
46+
initialY: 0
47+
};
48+
return acc;
49+
}, {});
4550
});
4651

4752
const lastPos = useRef({ x: 100, y: 100 });
4853
const OFFSET = 20;
4954

50-
const nodeRefs = useMemo(() => ({
51-
explorer: createRef(),
52-
vscode: createRef(),
53-
settings: createRef(),
54-
chrome: createRef(),
55-
terminal: createRef(),
56-
readme_txt: createRef(),
57-
}), []);
55+
const nodeRefs = useMemo(() => {
56+
return Object.keys(APP_REGISTRY).reduce((acc, key) => {
57+
acc[key] = createRef();
58+
return acc;
59+
}, {});
60+
}, []);
5861

5962
const taskbarApps = useMemo(() => {
6063
const pinned = ['explorer', 'vscode', 'settings', 'chrome', 'terminal'];
@@ -235,7 +238,7 @@ function Desktop() {
235238
<AppWindow
236239
key={name}
237240
title={APP_REGISTRY[name].title}
238-
src={APP_REGISTRY[name].src}
241+
AppComponent={APP_REGISTRY[name].component}
239242
imgSrc={APP_REGISTRY[name].imgSrc}
240243
zIndex={app.zIndex}
241244
fullscreen={app.fullscreen}

src/styles/DesktopApps.css

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/styles/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ body {
77
}
88

99
p {
10+
color: white;
1011
margin: 0;
1112
display: block;
1213
unicode-bidi: isolate;

0 commit comments

Comments
 (0)