mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-03 05:10:16 +03:00
* Adds a fallback mechanism so the desktop app routes tool operations to the local bundled backend when the user's self-hosted Stirling-PDF server goes offline, and disables tools in the UI that aren't supported locally. * `selfHostedServerMonitor.ts` independently polls the self-hosted server every 15s and exposes which tool endpoints are unavailable when it goes offline * `operationRouter.ts` intercepts operations destined for the self-hosted server and reroutes them to the local bundled backend when the monitor reports it offline * `useSelfHostedToolAvailability.ts` feeds the offline tool set into useToolManagement, disabling affected tools in the UI with a selfHostedOffline reason and banner warning - `SelfHostedOfflineBanner `is a dismissable (session-only) gray bar shown at the top of the UI when in self-hosted mode and the server goes offline. It shows:
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { useState, useEffect, useRef } from 'react';
|
|
import apiClient from '@app/services/apiClient';
|
|
import type { GroupEnabledResult } from '@app/types/groupEnabled';
|
|
|
|
export type { GroupEnabledResult };
|
|
|
|
/**
|
|
* Checks whether a named feature group is enabled on the backend.
|
|
* Returns { enabled: null } while loading, then true/false with an optional reason.
|
|
*/
|
|
export function useGroupEnabled(group: string): GroupEnabledResult {
|
|
const [result, setResult] = useState<GroupEnabledResult>({ enabled: null, unavailableReason: null });
|
|
const isMountedRef = useRef(true);
|
|
|
|
useEffect(() => {
|
|
isMountedRef.current = true;
|
|
return () => { isMountedRef.current = false; };
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
apiClient
|
|
.get<boolean>(`/api/v1/config/group-enabled?group=${encodeURIComponent(group)}`)
|
|
.then(res => { if (isMountedRef.current) setResult({ enabled: res.data, unavailableReason: null }); })
|
|
.catch(() => { if (isMountedRef.current) setResult({ enabled: false, unavailableReason: null }); });
|
|
}, [group]);
|
|
|
|
return result;
|
|
}
|