Repository navigation
Expand file tree
/
Copy pathApp.tsx
More file actions
82 lines (71 loc) · 2.29 KB
/
Copy pathApp.tsx
File metadata and controls
82 lines (71 loc) · 2.29 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
import { useState, useEffect } from 'react';
import ErrorBoundary from './components/ErrorBoundary';
import BootSequence from './components/BootSequence';
import CustomTerminalEnhanced from './components/CustomTerminalEnhanced';
import ScanLines from './components/ScanLines';
const readStorage = (kind: 'local' | 'session', key: string): string | null => {
try {
const storage = kind === 'local' ? window.localStorage : window.sessionStorage;
return storage.getItem(key);
} catch {
return null;
}
};
const writeStorage = (kind: 'local' | 'session', key: string, value: string): void => {
try {
const storage = kind === 'local' ? window.localStorage : window.sessionStorage;
storage.setItem(key, value);
} catch {
// The terminal remains usable when browser storage is unavailable.
}
};
function App() {
const [showBoot, setShowBoot] = useState(() => {
// Only show boot sequence once per session
const hasBooted = readStorage('session', 'hasBooted');
return !hasBooted;
});
const [scanLinesEnabled, setScanLinesEnabled] = useState(() => {
// Load scan lines preference from localStorage
const saved = readStorage('local', 'scanlines-enabled');
if (saved === null) {
return true;
}
return saved === 'true';
});
const handleBootComplete = () => {
writeStorage('session', 'hasBooted', 'true');
setShowBoot(false);
};
// Skip boot sequence with Escape key
useEffect(() => {
const handleKeyPress = (e: KeyboardEvent) => {
if (e.key === 'Escape' && showBoot) {
handleBootComplete();
}
};
window.addEventListener('keydown', handleKeyPress);
return () => window.removeEventListener('keydown', handleKeyPress);
}, [showBoot]);
// Update scan lines preference
useEffect(() => {
writeStorage('local', 'scanlines-enabled', scanLinesEnabled.toString());
}, [scanLinesEnabled]);
if (showBoot) {
return (
<ErrorBoundary>
<BootSequence onComplete={handleBootComplete} />
</ErrorBoundary>
);
}
return (
<ErrorBoundary>
<ScanLines enabled={scanLinesEnabled} />
<CustomTerminalEnhanced
onToggleScanLines={() => setScanLinesEnabled(!scanLinesEnabled)}
scanLinesEnabled={scanLinesEnabled}
/>
</ErrorBoundary>
);
}
export default App;