Skip to content

Commit f9955a9

Browse files
committed
(v0.1.4.4-alpha) Start Menu!
Simple Windows start menu can bbe opened by clicking the windows icon in the taskbar or by pressing metaKeys (win key or cmd key). Clicking anywhere else on the screen causes it to inactivate.
1 parent c0a4e9a commit f9955a9

File tree

3 files changed

+118
-7
lines changed

3 files changed

+118
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Your PC has been compromised by a group called the "HackClub". Can you regain co
88
- [X] Animations in the Lockscreen.
99
- [ ] A loading screen on lockscreen after correct pass slowly fade while loading desktop in the back + SOUND.
1010
- [X] Windows Design + Desktop Design (Done in v0.1.3... & v0.1.4... respectively)
11+
- [X] Windows start menu does nothing rn. (Done in v0.1.4.4)
1112
- [X] Minimizing window still takes up the zIndex and prevents from using it.(FIXED IN v0.1.3.3-alpha)
1213
- [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)
1314
- [X] Bug: Closing all apps still makes one of them active (visual) (FIXED: v0.1.3.4-alpha)
@@ -21,3 +22,4 @@ Your PC has been compromised by a group called the "HackClub". Can you regain co
2122
- [X] Make ~~opaque and~~ high zIndex when dragging desktop apps, to overlay the bottom objects. (Done in v0.1.4.3)
2223
- [X] BUG: In fullscreen clicking the app in taskbar toggles fullscreen, and it becomes not fullscreen. (Fixed in v0.1.4.3)
2324
- [X] BUG: Closing on fullscreen saves the state. On the opening again it starts in fullscreen. (Fixed in v0.1.4.3(1))
25+
- [ ] QOL: drag the window, even outside the bounding box, or the window keeping padding of like 1rem.

src/routes/desktop.jsx

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import '../styles/routes/desktop.css';
2-
import { Wifi, Volume2, Bell } from 'lucide-react';
2+
import { Wifi, Volume2, Bell, Search } from 'lucide-react';
33
import AppWindow, { INITIAL_Z, getNextZ } from '../core/WindowManager.jsx';
4-
import { createRef, useRef, useState, useMemo } from "react";
4+
import {createRef, useRef, useState, useMemo, useEffect} from "react";
55
import { APP_REGISTRY } from "../data/Apps.js";
66

77
import Draggable from 'react-draggable';
88
import { motion, AnimatePresence } from "framer-motion";
99

1010
function Desktop() {
11+
const [isStartMenuActive, setIsStartMenuActive] = useState(false);
12+
13+
const startMenuRef = useRef(null);
14+
15+
useEffect(() => {
16+
const handleClickOutside = (event) => {
17+
if (isStartMenuActive && startMenuRef.current && !startMenuRef.current.contains(event.target)) {
18+
if (!event.target.closest('#start-menu-icon')) {
19+
setIsStartMenuActive(false);
20+
}
21+
}
22+
};
23+
document.addEventListener("mousedown", handleClickOutside);
24+
return () => document.removeEventListener("mousedown", handleClickOutside);
25+
}, [isStartMenuActive]);
26+
1127
const [iconPositions, setIconPositions] = useState({
1228
explorer: { col: 1, row: 1 },
1329
vscode: { col: 1, row: 2 },
@@ -149,9 +165,30 @@ function Desktop() {
149165
}));
150166
}
151167

168+
useEffect(() => {
169+
const handleKey = (e) => {
170+
if (e.metaKey) {
171+
e.preventDefault();
172+
173+
setIsStartMenuActive(!isStartMenuActive);
174+
}
175+
};
176+
177+
window.addEventListener("keydown", handleKey);
178+
return () => window.removeEventListener("keydown", handleKey);
179+
});
180+
152181
return (
153-
<div className="desktop" onMouseDown={() => setSelectedIcon(null)}>
154-
<div className="desktop-grid" style={{ position: 'absolute', inset: 0, display: 'grid', zIndex: 1 }}>
182+
<div className="desktop" onMouseDown={() => {
183+
setSelectedIcon(null);
184+
}}>
185+
<div
186+
className="desktop-grid"
187+
style={{ position: 'absolute', inset: 0, display: 'grid', zIndex: 1 }}
188+
onClick={() => {
189+
setIsStartMenuActive(false);
190+
}}
191+
>
155192
{Object.keys(iconPositions).map((id) => (
156193
<Draggable
157194
key={id}
@@ -213,6 +250,16 @@ function Desktop() {
213250
) : null
214251
)}
215252

253+
<div
254+
ref={startMenuRef}
255+
className={`start-menu ${isStartMenuActive ? "active" : ""}`}
256+
>
257+
<div className={"start-search"}>
258+
<Search className={"start-search-icon"} />
259+
<input className={"start-search-bar"} type={"text"}/>
260+
</div>
261+
</div>
262+
216263
<div className={`taskbar ${ isAnyFullScreen ? 'is-fullscreen' : ''}`} onClick={(e) => e.stopPropagation()}>
217264
<div className="apps">
218265
<AnimatePresence mode="popLayout">
@@ -223,11 +270,13 @@ function Desktop() {
223270
exit={{ opacity: 0, width: 0, scale: 0.5 }}
224271
transition={{ type: "spring", stiffness: 300, damping: 30 }}
225272
className="app-item"
273+
onClick={() => setIsStartMenuActive(!isStartMenuActive)}
226274
>
227-
<div className="taskbar-app" id="start-menu">
275+
<div className="taskbar-app" id="start-menu-icon">
228276
<img className={"taskbar-app-icon"} src={"/assets/icons/Windows.svg"} draggable="false" alt="icon" />
229277
</div>
230278
</motion.div>
279+
231280
{taskbarApps.map(id => (
232281
<motion.div
233282
key={id}

src/styles/routes/desktop.css

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,68 @@
203203
pointer-events: none;
204204
}
205205

206-
.start-menu{
207-
background-image: url("../../assets/icons/Windows.svg");
206+
.start-menu {
207+
bottom: 3.5rem;
208+
left: calc(50vw - 25rem/2);
209+
210+
z-index: 10000;
211+
212+
position: fixed;
213+
height: 28rem;
214+
width: 25rem;
215+
216+
/*min-width: 25rem;*/
217+
opacity: 0.5;
218+
219+
/*background-color: var(--gray);*/
220+
221+
backdrop-filter: blur(2rem) brightness(0.2);
222+
transition: 0.5s var(--hover-animation-type);
223+
224+
border-top: 1px solid var(--border);
225+
border-radius: var(--radius);
226+
227+
transform: translateY(200%);
228+
229+
display: flex;
230+
flex-direction: column;
231+
align-items: center;
232+
/*justify-content: center;*/
233+
}
234+
.start-menu.active {
235+
transform: translateY(0%);
236+
opacity: 1;
237+
}
238+
239+
.start-search {
240+
display: flex;
241+
flex-direction: row;
242+
align-items: center;
243+
justify-content: center;
244+
margin-top: 1.5rem;
245+
height: 2.1rem;
246+
width: 85%;
247+
248+
background: var(--background);
249+
250+
border-radius: 200rem;
251+
252+
border: 1px solid var(--border);
253+
254+
/*padding: 0.25rem;*/
255+
}
256+
257+
.start-search-icon {
258+
margin-left: 0.6rem;
259+
margin-right: 0.25rem;
260+
}
261+
262+
.start-search-bar{
263+
width: 100%;
264+
height: 100%;
265+
background: transparent;
266+
border: none;
267+
outline: none;
208268
}
209269

210270
.taskbar-app-icon {

0 commit comments

Comments
 (0)