File size: 5,017 Bytes
5c86297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React from 'react';
import {
  useFloating,
  offset,
  flip,
  shift,
  autoUpdate,
  useDismiss,
  useRole,
  useInteractions,
  FloatingPortal,
} from '@floating-ui/react';
import { useProcessStore } from '../../stores/useProcessStore';
import { useOSStore } from '../../stores/useOSStore';

interface SystemTrayProcessFlyoutProps {
  isOpen: boolean;
  onOpenChange: (open: boolean) => void;
  children: (ref: (node: HTMLElement | null) => void, props: Record<string, unknown>) => React.ReactNode;
}

export const SystemTrayProcessFlyout: React.FC<SystemTrayProcessFlyoutProps> = ({
  isOpen,
  onOpenChange,
  children,
}) => {
  const processes = useProcessStore(s => s.processes);
  const activeProcesses = Object.values(processes).filter(p => p.status === 'running');
  const openWindow = useOSStore(s => s.openWindow);

  const {
    refs: { setReference, setFloating },
    floatingStyles,
    context,
  } = useFloating({
    open: isOpen,
    onOpenChange,
    placement: 'top-end',
    middleware: [
      offset(10),
      flip({ padding: 10 }),
      shift({ padding: 10 }),
    ],
    whileElementsMounted: autoUpdate,
  });

  const dismiss = useDismiss(context, { outsidePress: true, escapeKey: true });
  const role = useRole(context, { role: 'dialog' });
  const { getReferenceProps, getFloatingProps } = useInteractions([dismiss, role]);

  return (
    <>
      {children(setReference, getReferenceProps())}

      {isOpen && (
        <FloatingPortal>
          <div
            ref={setFloating}
            style={floatingStyles}
            {...getFloatingProps()}
            className="z-[90] w-80 bg-paper-white border-[3px] border-ink-black shadow-[6px_6px_0px_0px_#1E293B] flex flex-col p-3 select-none animate-fade-in"
          >
            {/* Header */}
            <div className="flex items-center justify-between border-b-2 border-ink-black pb-2 mb-2 bg-[#0284c7] text-white px-2 py-1 -mx-3 -mt-3">
              <div className="flex items-center gap-1.5">
                <span className="material-symbols-outlined text-sm animate-spin">autorenew</span>
                <span className="font-arcade text-[9px] font-bold tracking-wider">PROCESS MONITOR</span>
              </div>
              <span className="font-arcade text-[8px] font-bold bg-[#facc15] text-ink-black px-1.5 py-0.5 border border-ink-black">
                {activeProcesses.length} ACTIVE
              </span>
            </div>

            {/* Process List */}
            <div className="flex flex-col gap-2 max-h-56 overflow-y-auto custom-scrollbar my-1">
              {activeProcesses.length === 0 ? (
                <div className="text-center py-4 text-xs font-window-title text-slate-500 font-bold">
                  No background processes running
                </div>
              ) : (
                activeProcesses.map((proc) => (
                  <div
                    key={proc.pid}
                    className="p-2 border-2 border-ink-black bg-slate-50 flex flex-col gap-1 shadow-[2px_2px_0_0_#1E293B]"
                  >
                    <div className="flex items-center justify-between">
                      <span className="font-window-title text-xs font-bold text-ink-black truncate max-w-[170px]">
                        {proc.title}
                      </span>
                      <span className="font-arcade text-[7px] font-extrabold bg-[#39ff14] text-ink-black px-1 py-0.2 border border-ink-black">
                        RUNNING
                      </span>
                    </div>
                    <div className="flex items-center justify-between font-arcade text-[8px] text-slate-500">
                      <span>TYPE: {proc.appId.toUpperCase()}</span>
                      <span>PID: {proc.pid.slice(-6)}</span>
                    </div>
                  </div>
                ))
              )}
            </div>

            {/* Footer / Terminal launcher */}
            <div className="pt-2 border-t-2 border-ink-black/20 flex items-center justify-between gap-2 mt-1">
              <button
                onClick={() => {
                  onOpenChange(false);
                  openWindow('terminal');
                }}
                className="flex-1 py-1 px-2 bg-[#39ff14] hover:bg-[#28e007] border-2 border-ink-black text-ink-black font-window-title text-[11px] font-bold flex items-center justify-center gap-1.5 transition-colors cursor-pointer"
              >
                <span className="material-symbols-outlined text-xs">terminal</span>
                Open Terminal (ps)
              </button>
              <button
                onClick={() => onOpenChange(false)}
                className="py-1 px-2.5 bg-slate-200 hover:bg-slate-300 border-2 border-ink-black text-ink-black font-window-title text-[11px] font-bold transition-colors cursor-pointer"
              >
                Close
              </button>
            </div>
          </div>
        </FloatingPortal>
      )}
    </>
  );
};