File size: 4,358 Bytes
29df79a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
105
106
107
108
import { Component, type ReactNode, type ErrorInfo } from 'react';
import { RotateCcw, AlertOctagon, Trash2 } from 'lucide-react';

interface RootErrorBoundaryProps {
  children: ReactNode;
}

interface RootErrorBoundaryState {
  hasError: boolean;
  error: Error | null;
}

export default class RootErrorBoundary extends Component<
  RootErrorBoundaryProps,
  RootErrorBoundaryState
> {
  constructor(props: RootErrorBoundaryProps) {
    super(props);
    this.state = { hasError: false, error: null };
  }

  static getDerivedStateFromError(error: Error): RootErrorBoundaryState {
    return { hasError: true, error };
  }

  componentDidCatch(error: Error, errorInfo: ErrorInfo) {
    console.error('[RootErrorBoundary] Fatal system error caught at OS root:', error, errorInfo);
  }

  handleReboot = () => {
    window.location.reload();
  };

  handleHardReset = () => {
    try {
      localStorage.clear();
      sessionStorage.clear();
    } catch (_) {}
    window.location.reload();
  };

  render() {
    if (this.state.hasError) {
      return (
        <div className="fixed inset-0 z-[99999] bg-[#030712] text-white flex flex-col items-center justify-center p-6 font-mono select-none overflow-auto">
          {/* CRT scanline simulation */}
          <div className="absolute inset-0 pointer-events-none bg-[radial-gradient(ellipse_at_center,transparent_0%,rgba(0,0,0,0.4)_100%)]" />

          <div className="relative max-w-xl w-full bg-[#0b0f19] border-[3px] border-rose-500 rounded-lg p-6 shadow-[8px_8px_0px_0px_rgba(244,63,94,0.3)] flex flex-col gap-5">
            {/* Header */}
            <div className="flex items-center gap-3 text-rose-400 border-b border-rose-950 pb-3">
              <div className="p-2 bg-rose-500/10 rounded border border-rose-500/30">
                <AlertOctagon className="w-6 h-6 text-rose-500 animate-pulse" />
              </div>
              <div>
                <h1 className="text-sm font-bold tracking-wider uppercase text-rose-300 font-arcade">
                  ALGOSPACED_RECOVERY_CONSOLE
                </h1>
                <p className="text-[10px] text-rose-400/75 mt-0.5">
                  STOP: 0x000000D1 • DESKTOP_THREAD_EXCEPTION
                </p>
              </div>
            </div>

            {/* Error Details */}
            <div className="space-y-2">
              <span className="text-[11px] text-slate-400 uppercase font-semibold tracking-wider block">
                Fault Trace:
              </span>
              <div className="bg-[#020617] border border-slate-800 rounded p-3 text-[11px] text-rose-300 font-mono leading-relaxed max-h-36 overflow-y-auto custom-scrollbar break-all">
                {this.state.error?.message || 'A fatal system exception was trapped by the OS kernel.'}
              </div>
            </div>

            <p className="text-xs text-slate-300 leading-relaxed">
              A recoverable exception occurred in the primary desktop shell. Your local data and progress records are safely preserved in storage.
            </p>

            {/* Action Bar */}
            <div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-end gap-3 pt-3 border-t border-slate-800">
              <button
                type="button"
                onClick={this.handleHardReset}
                className="px-4 py-2 bg-slate-800 hover:bg-slate-700 text-slate-300 rounded text-xs font-bold transition-all border border-slate-700 flex items-center justify-center gap-2 cursor-pointer"
                title="Clears cached session data and resets workspace state"
              >
                <Trash2 className="w-3.5 h-3.5 text-slate-400" />
                <span>Reset Cache & Reboot</span>
              </button>

              <button
                type="button"
                onClick={this.handleReboot}
                className="px-4 py-2 bg-rose-600 hover:bg-rose-500 text-white rounded text-xs font-bold transition-all shadow-[2px_2px_0px_0px_#000] active:translate-y-0.5 active:shadow-none flex items-center justify-center gap-2 cursor-pointer"
              >
                <RotateCcw className="w-3.5 h-3.5" />
                <span>Reboot AlgoSpaced OS</span>
              </button>
            </div>
          </div>
        </div>
      );
    }

    return this.props.children;
  }
}