Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions SparkyFitnessMobile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import {
} from './src/services/autoSyncCoordinator';
import { initializeTheme } from './src/services/themeService';
import { loadActiveDraft, clearDraft } from './src/services/workoutDraftService';
import { initLogService } from './src/services/LogService';
import { addLog, initLogService } from './src/services/LogService';
import { initNotifications } from './src/services/notifications';
import { ensureTimezoneBootstrapped } from './src/services/api/preferencesApi';
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
Expand Down Expand Up @@ -130,7 +130,9 @@ function AppContent() {
const route = config ? 'Tabs' : 'Onboarding';
setInitialRoute(route);
setLinkingEnabled(route === 'Tabs');
} catch {
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
Comment thread
apedley marked this conversation as resolved.
addLog(`[App] Failed to load active server config on startup: ${message}`, 'ERROR');
setInitialRoute('Onboarding');
} finally {
await SplashScreen.hideAsync();
Expand Down Expand Up @@ -330,7 +332,8 @@ function AppContent() {
},
});
} catch (error) {
console.error('[App] Auto sync on open failed:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Auto sync on open failed: ${message}`, 'ERROR');
} finally {
if (!committed) release();
}
Expand Down Expand Up @@ -358,23 +361,25 @@ function AppContent() {

// Initialize log service (warms cache, prunes old logs, registers AppState listener)
initLogService().catch(error => {
console.error('[App] Failed to initialize log service:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Failed to initialize log service: ${message}`, 'ERROR');
});

const initializeSyncServices = async () => {
// Bootstrap timezone before any sync path is configured so the server
// has a stable timezone for the very first sync.
const timezone = await ensureTimezoneBootstrapped();
if (!timezone) {
console.warn('[App] Timezone bootstrap did not resolve a timezone before sync setup.');
addLog('[App] Timezone bootstrap did not resolve a timezone before sync setup.', 'WARNING');
}

if (cancelled) return;

try {
await configureBackgroundSync();
} catch (error) {
console.error('[App] Failed to configure background sync:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Failed to configure background sync: ${message}`, 'ERROR');
}

if (cancelled || Platform.OS !== 'ios') return;
Expand All @@ -399,23 +404,27 @@ function AppContent() {

performBackgroundSync('healthkit-observer')
.catch(error => {
console.error('[App] Observer-triggered sync failed:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Observer-triggered sync failed: ${message}`, 'ERROR');
})
.finally(() => {
release();
});
});
} catch (error) {
console.error('[App] Failed to configure HealthKit observers:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Failed to configure HealthKit observers: ${message}`, 'ERROR');
}
};

initializeSyncServices().catch(error => {
console.error('[App] Failed to initialize sync services:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Failed to initialize sync services: ${message}`, 'ERROR');
});

flushPendingHealthSyncCacheRefresh().catch(error => {
console.error('[App] Failed to flush pending health sync refresh:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Failed to flush pending health sync refresh: ${message}`, 'ERROR');
});

return () => {
Expand Down Expand Up @@ -457,7 +466,8 @@ function AppContent() {

triggerColdStartSync().catch(error => {
setForegroundAutoSyncWindowState(false);
console.error('[App] Cold-start sync on open failed:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Cold-start sync on open failed: ${message}`, 'ERROR');
});
}, [initialRoute, setForegroundAutoSyncWindowState]);

Expand Down Expand Up @@ -511,7 +521,8 @@ function AppContent() {
await triggerAutoSyncRef.current(config.id, safeCleanup);
} catch (error) {
setForegroundAutoSyncWindowState(false);
console.error('[App] Foreground-return sync on open failed:', error);
const message = error instanceof Error ? error.message : String(error);
addLog(`[App] Foreground-return sync on open failed: ${message}`, 'ERROR');
}
});

Expand Down Expand Up @@ -698,9 +709,7 @@ function AppContent() {
name="Logs"
component={SafeLogs}
options={{
headerShown: true,
title: 'Logs',
headerBackTitle: 'Back',
headerShown: false,
}}
/>
<Stack.Screen
Expand Down
Loading
Loading