Spaces:
Running
Running
Download algospaced-ui/src/components/desktop/SystemTrayProcessFlyout.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 5.02 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/desktop/SystemTrayProcessFlyout.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/desktop/SystemTrayProcessFlyout.tsx
-
curl -L -o SystemTrayProcessFlyout.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/desktop/SystemTrayProcessFlyout.tsx
5.02 kB
| 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> | |
| )} | |
| </> | |
| ); | |
| }; | |