main function Overview

void main()

App entry point. Boots Supabase, spawns DuTaToApp, and lazily starts Firebase + notification services in the background so the UI paints without waiting on native init.

Implementation

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // -- Supabase (must be before runApp — auth state drives routing) --
  bool supabaseReady = false;
  try {
    await SupabaseConfig.load();
    if (SupabaseConfig.isConfigured &&
        SupabaseConfig.mode == InstanceMode.custom) {
      await Supabase.initialize(
        url: SupabaseConfig.url,
        anonKey: SupabaseConfig.anonKey,
        authOptions: const FlutterAuthClientOptions(
          authFlowType: AuthFlowType.pkce,
        ),
      );
      supabaseReady = true;
    }
  } catch (e) {
    dev.log('Supabase init failed: $e', name: 'main');
  }

  // -- Local LLM cleanup (one-time, reclaims disk space on devices that
  // downloaded GGUF weights before the feature was gated off). Runs only
  // when `EnvConfig.enableLocalLlm` is false AND the versioned done-flag
  // isn't stamped yet; otherwise no-op. Awaited so storage writes settle
  // before the first read in `selectedAiProviderProvider`.
  if (!kIsWeb) {
    try {
      await const LocalLlmCleanupService().run(const FlutterSecureStorage());
    } catch (e) {
      dev.log('LocalLlmCleanupService failed: $e', name: 'main');
    }
  }

  // Show the UI immediately — Firebase & notifications init in the background.
  runApp(ProviderScope(child: DuTaToApp(supabaseReady: supabaseReady)));
}