-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
104 lines (91 loc) · 3.17 KB
/
App.jsx
File metadata and controls
104 lines (91 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, { useState, useEffect } from 'react';
import { WindowManagerProvider, useWindowManager } from './context/WindowManagerContext';
import { AnimatePresence } from 'framer-motion';
import BootSequence from './components/BootSequence';
import QuoteScreen from './components/QuoteScreen';
import Desktop from './components/Desktop';
import Window from './components/Window';
import LoginScreen from './components/LoginScreen';
import ShutdownSequence from './components/ShutdownSequence';
const DesktopEnvironment = ({ wallpaper, onLogOff, onPowerOff, onChangeWallpaper }) => {
const { windows, openWindow, closeWindow, focusWindow, focusedWindowId } = useWindowManager();
useEffect(() => {
// No default apps open on startup
}, []);
return (
<Desktop
wallpaper={wallpaper}
onLogOff={onLogOff}
onPowerOff={onPowerOff}
onChangeWallpaper={onChangeWallpaper}
>
{/* Render Windows */}
{windows.map((win) => (
<Window
key={win.id}
title={win.title}
icon={win.icon}
isFocused={focusedWindowId === win.id}
onFocus={() => focusWindow(win.id)}
onClose={() => closeWindow(win.id)}
initialPosition={{ x: 50 + (windows.indexOf(win) * 20), y: 50 + (windows.indexOf(win) * 20) }}
>
{win.component}
</Window>
))}
</Desktop>
);
};
function App() {
const [status, setStatus] = useState('quote'); // quote, booting, login, desktop, shutdown
const [wallpaper, setWallpaper] = useState('/wallpaper_1.jpg');
const [shutdownDestination, setShutdownDestination] = useState('login');
const wallpapers = [
'/wallpaper_1.jpg',
'/wallpaper_2.jpg',
'/wallpaper_3.jpg'
];
const handleCycleWallpaper = () => {
const currentIndex = wallpapers.indexOf(wallpaper);
const nextIndex = (currentIndex + 1) % wallpapers.length;
setWallpaper(wallpapers[nextIndex]);
};
useEffect(() => {
const randomPick = wallpapers[Math.floor(Math.random() * wallpapers.length)];
setWallpaper(randomPick);
}, []);
return (
<WindowManagerProvider>
<AnimatePresence mode="wait">
{status === 'quote' && (
<QuoteScreen key="quote" onComplete={() => setStatus('booting')} />
)}
{status === 'booting' && (
<BootSequence key="boot" onComplete={() => setStatus('login')} />
)}
{status === 'login' && (
<LoginScreen key="login" onLogin={() => setStatus('desktop')} wallpaper={wallpaper} />
)}
{status === 'desktop' && (
<DesktopEnvironment
key="desktop"
wallpaper={wallpaper}
onLogOff={() => {
setShutdownDestination('login');
setStatus('shutdown');
}}
onPowerOff={() => {
setShutdownDestination('booting');
setStatus('shutdown');
}}
onChangeWallpaper={handleCycleWallpaper}
/>
)}
{status === 'shutdown' && (
<ShutdownSequence key="shutdown" onComplete={() => setStatus(shutdownDestination)} />
)}
</AnimatePresence>
</WindowManagerProvider>
);
}
export default App;