import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

export function TrayBridge() {
  const navigate = useNavigate();

  useEffect(() => {
    const onNavigate = (to: unknown) => {
      navigate(String(to));
    };

    const onLogout = () => {
      localStorage.removeItem('launcher_config');
      navigate('/login');
    };

    window.electron.ipcRenderer.on('tray-navigate', onNavigate);
    window.electron.ipcRenderer.on('tray-logout', onLogout);

    return () => {
      window.electron.ipcRenderer.removeAllListeners('tray-navigate');
      window.electron.ipcRenderer.removeAllListeners('tray-logout');
    };
  }, [navigate]);

  return null;
}
