Skip to content

Commit 0821b5a

Browse files
committed
(v0.1.4.6-alpha) Bug Fix (#3) + QOL changes
drag the window, even outside the bounding box, or the window keeping padding of like 2.5rem Clicking on the windows icon when the start menu is active causes a jittering effect and doesn't close it.
1 parent f8f35ff commit 0821b5a

File tree

3 files changed

+57
-26
lines changed

3 files changed

+57
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Your PC has been compromised by a group called the "HackClub". Can you regain co
2222
- [X] Make ~~opaque and~~ high zIndex when dragging desktop apps, to overlay the bottom objects. (Done in v0.1.4.3)
2323
- [X] BUG: In fullscreen clicking the app in taskbar toggles fullscreen, and it becomes not fullscreen. (Fixed in v0.1.4.3)
2424
- [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.
26-
- [ ] BUG: Clicking on the windows icon when the start menu is active causes a jittering effect and doesn't close it.
25+
- [X] QOL: drag the window, even outside the bounding box, or the window keeping padding of like 2.5rem.(Fixed in v0.1.4.6)
26+
- [X] BUG (Issue #3): Clicking on the windows icon when the start menu is active causes a jittering effect and doesn't close it. (Fixed in v0.1.4.6)
2727
- [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)
2828
- [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/core/WindowManager.jsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default function AppWindow({
2020
const DEFAULT_WIDTH = 600;
2121
const DEFAULT_HEIGHT = 400;
2222
const TASKBAR_HEIGHT = 48;
23+
const PADDING = 36;
2324

2425
const [state, setState] = useState({
2526
x: posX,
@@ -35,21 +36,47 @@ export default function AppWindow({
3536
requestAnimationFrame(() => setOpening(false));
3637
}, []);
3738

39+
const handleDrag = (e, d) => {
40+
setState(prev => ({ ...prev, x: d.x, y: d.y }));
41+
setIsInteracting(true);
42+
};
43+
44+
const handleDragStop = (e, d) => {
45+
let newX = d.x;
46+
let newY = d.y;
47+
48+
if (newX > window.innerWidth - PADDING) {
49+
newX = window.innerWidth - PADDING;
50+
}
51+
if (newX < -state.width + PADDING) {
52+
newX = -state.width + PADDING;
53+
}
54+
if (newY > window.innerHeight - TASKBAR_HEIGHT - PADDING) {
55+
newY = window.innerHeight - TASKBAR_HEIGHT - PADDING;
56+
}
57+
58+
if (newY < 0) {
59+
newY = 0;
60+
}
61+
62+
setState(prev => ({ ...prev, x: newX, y: newY }));
63+
setIsInteracting(false);
64+
};
65+
3866

3967
return (
4068
<Rnd
41-
bounds="parent"
69+
bounds=""
4270
dragGrid={[1, 1]}
4371
size={fullscreen ? { width: "100vw", height: window.innerHeight - 48 } : { width: state.width, height: state.height }}
4472
position={fullscreen ? { x: 0, y: 0 } : { x: state.x, y: state.y }}
4573

4674
disableDragging={fullscreen}
4775
enableResizing={!fullscreen}
4876

49-
onDragStop={(e, d) => {
50-
setState(prev => ({ ...prev, x: d.x, y: d.y }));
51-
setIsInteracting(false);
52-
}}
77+
onDrag={handleDrag}
78+
onDragStop={handleDragStop}
79+
5380
onResizeStop={(e, direction, ref, delta, position) => {
5481
setState({
5582
width: ref.offsetWidth,
@@ -60,7 +87,6 @@ export default function AppWindow({
6087
}}
6188
onDragStart={() => { onFocus(); setIsInteracting(true); }}
6289
onResizeStart={() => setIsInteracting(true)}
63-
onDrag={() => setIsInteracting(true)}
6490

6591
dragHandleClassName="titlebar"
6692
style={
@@ -71,6 +97,7 @@ export default function AppWindow({
7197
}
7298
minWidth={300}
7399
minHeight={200}
100+
74101
maxHeight={window.innerHeight - TASKBAR_HEIGHT}
75102
maxWidth={window.innerWidth}
76103
>

src/routes/desktop.jsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ function Desktop() {
1212
const [isStartMenuActive, setIsStartMenuActive] = useState(false);
1313

1414
const startMenuRef = useRef(null);
15+
const menuActiveRef = useRef(isStartMenuActive);
16+
useEffect(() => {
17+
menuActiveRef.current = isStartMenuActive;
18+
}, [isStartMenuActive]);
19+
1520
useEffect(() => {
1621
const handleClickOutside = (event) => {
1722
if (isStartMenuActive && startMenuRef.current && !startMenuRef.current.contains(event.target)) {
@@ -20,10 +25,22 @@ function Desktop() {
2025
}
2126
}
2227
};
28+
2329
document.addEventListener("mousedown", handleClickOutside);
2430
return () => document.removeEventListener("mousedown", handleClickOutside);
2531
}, [isStartMenuActive]);
2632

33+
useEffect(() => {
34+
const handleKey = (e) => {
35+
if (e.metaKey) {
36+
e.preventDefault();
37+
setIsStartMenuActive(prev => !prev);
38+
}
39+
};
40+
window.addEventListener("keydown", handleKey);
41+
return () => window.removeEventListener("keydown", handleKey);
42+
}, []);
43+
2744
const [iconPositions, setIconPositions] = useState({
2845
explorer: { col: 1, row: 1 },
2946
vscode: { col: 1, row: 2 },
@@ -168,29 +185,13 @@ function Desktop() {
168185
}));
169186
}
170187

171-
useEffect(() => {
172-
const handleKey = (e) => {
173-
if (e.metaKey) {
174-
e.preventDefault();
175-
176-
setIsStartMenuActive(!isStartMenuActive);
177-
}
178-
};
179-
180-
window.addEventListener("keydown", handleKey);
181-
return () => window.removeEventListener("keydown", handleKey);
182-
});
183-
184188
return (
185189
<div className="desktop" onMouseDown={() => {
186190
setSelectedIcon(null);
187191
}}>
188192
<div
189193
className="desktop-grid"
190194
style={{ position: 'absolute', inset: 0, display: 'grid', zIndex: 1 }}
191-
onClick={() => {
192-
setIsStartMenuActive(false);
193-
}}
194195
>
195196
{Object.keys(iconPositions).map((id) => (
196197
<Draggable
@@ -263,7 +264,7 @@ function Desktop() {
263264
</div>
264265
</div>
265266

266-
<div className={`taskbar ${ isAnyFullScreen ? 'is-fullscreen' : ''}`} onClick={(e) => e.stopPropagation()}>
267+
<div className={`taskbar ${ isAnyFullScreen ? 'is-fullscreen' : ''}`}>
267268
<div className="apps">
268269
<AnimatePresence mode="popLayout">
269270
<motion.div
@@ -273,7 +274,10 @@ function Desktop() {
273274
exit={{ opacity: 0, width: 0, scale: 0.5 }}
274275
transition={{ type: "spring", stiffness: 300, damping: 30 }}
275276
className="app-item"
276-
onClick={() => setIsStartMenuActive(!isStartMenuActive)}
277+
onMouseDown={(e) => {
278+
e.stopPropagation();
279+
setIsStartMenuActive(prev => !prev);
280+
}}
277281
>
278282
<div className="taskbar-app" id="start-menu-icon">
279283
<img className={"taskbar-app-icon"} src={"/assets/icons/Windows.svg"} draggable="false" alt="icon" />

0 commit comments

Comments
 (0)