mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 02:54:06 +02:00
# Description of Changes Improve loading speed of desktop app by loading a default config until the backend has spawned.
25 lines
724 B
TypeScript
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,
|
|
};
|
|
}
|