Desktop connection SaaS: config, billing, team support (#5768)

Co-authored-by: James Brunton <[email protected]>
Co-authored-by: James Brunton <[email protected]>
This commit is contained in:
ConnorYoh
2026-02-25 14:13:07 +00:00
committed by GitHub
co-authored by James Brunton James Brunton
parent 86072ec91a
commit 5c39acecd8
76 changed files with 6231 additions and 119 deletions
@@ -10,8 +10,27 @@ import { DESKTOP_DEFAULT_APP_CONFIG } from '@app/config/defaultAppConfig';
import { connectionModeService } from '@app/services/connectionModeService';
import { tauriBackendService } from '@app/services/tauriBackendService';
import { authService } from '@app/services/authService';
import { endpointAvailabilityService } from '@app/services/endpointAvailabilityService';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { isTauri } from '@tauri-apps/api/core';
import { SaaSTeamProvider } from '@app/contexts/SaaSTeamContext';
import { SaasBillingProvider } from '@app/contexts/SaasBillingContext';
import { SaaSCheckoutProvider } from '@app/contexts/SaaSCheckoutContext';
import { CreditModalBootstrap } from '@app/components/shared/modals/CreditModalBootstrap';
// Common tool endpoints to preload for faster first-use
const COMMON_TOOL_ENDPOINTS = [
'/api/v1/misc/compress-pdf',
'/api/v1/general/merge-pdfs',
'/api/v1/general/split-pages',
'/api/v1/convert/pdf/img',
'/api/v1/convert/img/pdf',
'/api/v1/general/rotate-pdf',
'/api/v1/misc/add-watermark',
'/api/v1/security/add-password',
'/api/v1/security/remove-password',
'/api/v1/general/extract-pages',
];
/**
* Desktop application providers
@@ -53,6 +72,39 @@ export function AppProviders({ children }: { children: ReactNode }) {
const shouldMonitorBackend = setupComplete && !isFirstLaunch && connectionMode === 'saas';
useBackendInitializer(shouldMonitorBackend);
// Preload endpoint availability after backend is healthy
useEffect(() => {
if (!shouldMonitorBackend) {
return; // Only preload in SaaS mode with bundled backend
}
const preloadEndpoints = async () => {
const backendHealthy = tauriBackendService.isBackendHealthy();
if (backendHealthy) {
console.debug('[AppProviders] Preloading common tool endpoints');
await endpointAvailabilityService.preloadEndpoints(
COMMON_TOOL_ENDPOINTS,
tauriBackendService.getBackendUrl()
);
console.debug('[AppProviders] Endpoint preloading complete');
}
};
// Subscribe to backend status changes
const unsubscribe = tauriBackendService.subscribeToStatus((status) => {
if (status === 'healthy') {
preloadEndpoints();
}
});
// Also check immediately in case backend is already healthy
if (tauriBackendService.isBackendHealthy()) {
preloadEndpoints();
}
return unsubscribe;
}, [shouldMonitorBackend]);
useEffect(() => {
if (!authChecked) {
return;
@@ -148,10 +200,17 @@ export function AppProviders({ children }: { children: ReactNode }) {
autoFetch: false,
}}
>
<DesktopConfigSync />
<DesktopBannerInitializer />
<SaveShortcutListener />
{children}
<SaaSTeamProvider>
<SaasBillingProvider>
<SaaSCheckoutProvider>
<DesktopConfigSync />
<DesktopBannerInitializer />
<SaveShortcutListener />
<CreditModalBootstrap />
{children}
</SaaSCheckoutProvider>
</SaasBillingProvider>
</SaaSTeamProvider>
</ProprietaryAppProviders>
);
}