Files
Stirling-PDF/frontend/src/desktop/hooks/useBackendHealth.ts
T
James BruntonandGitHub 044bf3c2aa Improve loading speed of desktop app (#4865)
# Description of Changes
Improve loading speed of desktop app by loading a default config until
the backend has spawned.
2025-11-11 11:54:43 +00:00

25 lines
724 B
TypeScript

import { useEffect, useState, useCallback } from 'react';
import { backendHealthMonitor } from '@app/services/backendHealthMonitor';
import type { BackendHealthState } from '@app/types/backendHealth';
/**
* Hook to read the shared backend health monitor state.
* All consumers subscribe to a single poller managed by backendHealthMonitor.
*/
export function useBackendHealth() {
const [health, setHealth] = useState<BackendHealthState>(() => backendHealthMonitor.getSnapshot());
useEffect(() => {
return backendHealthMonitor.subscribe(setHealth);
}, []);
const checkHealth = useCallback(async () => {
return backendHealthMonitor.checkNow();
}, []);
return {
...health,
checkHealth,
};
}