# Description of Changes Makes the desktop options to sign in with your Stirling account, or sign into self-hosted: <img width="608" height="456" alt="image" src="https://github.com/user-attachments/assets/a49988ab-db3f-4333-b242-790aee5c07c6" /> The first option still runs everything locally, just enforces that you've signed in for now. Future work will enable sending operations that can't be run locally to the server.
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useBackendHealth } from '@app/hooks/useBackendHealth';
|
|
import { useEndpointConfig } from '@app/hooks/useEndpointConfig';
|
|
import { tauriBackendService } from '@app/services/tauriBackendService';
|
|
|
|
/**
|
|
* Hook to initialize backend and monitor health
|
|
* @param enabled - Whether to initialize the backend (default: true)
|
|
*/
|
|
export function useBackendInitializer(enabled = true) {
|
|
const { status, checkHealth } = useBackendHealth();
|
|
const { backendUrl } = useEndpointConfig();
|
|
|
|
useEffect(() => {
|
|
// Skip if disabled
|
|
if (!enabled) {
|
|
return;
|
|
}
|
|
|
|
// Skip if backend already running
|
|
if (tauriBackendService.isBackendRunning()) {
|
|
void checkHealth();
|
|
return;
|
|
}
|
|
|
|
const initializeBackend = async () => {
|
|
try {
|
|
await tauriBackendService.startBackend(backendUrl);
|
|
|
|
// Begin health checks after a short delay
|
|
setTimeout(() => {
|
|
void checkHealth();
|
|
}, 500);
|
|
} catch (error) {
|
|
console.error('[BackendInitializer] Failed to start backend:', error);
|
|
}
|
|
};
|
|
|
|
// Only start backend if it's not already starting/healthy
|
|
if (status !== 'healthy' && status !== 'starting') {
|
|
void initializeBackend();
|
|
}
|
|
}, [enabled, status, backendUrl, checkHealth]);
|
|
}
|