main function

void main()

Main entry point for the application.

Implementation

void main() async {
  // We require [async] because we asynchronously [await] the window manager
  // below. Often, `main()` will include just the call [runApp].

  // Optionally we can globally remove [debugPrint] messages.
  //
  // debugPrint = (String? message, {int? wrapWidth}) {
  //   null;
  // };

  // Ensure Flutter bindings are initialized for async operations, in particular
  // to set the Linux desktop window [title].

  WidgetsFlutterBinding.ensureInitialized();

  // CRITICAL: Set app directory name BEFORE any Pod operations
  // This must be called early to prevent double-slash bug in file paths
  // Without this, paths become //data/places.json instead of geopod/data/places.json.
  await setAppDirName('geopod');

  // Initialize encrypted places service to load persistent flags
  // This improves performance by avoiding repeated checks.
  await EncryptedPlacesService.initialize();

  // Configure SolidAuthHandler with app-specific settings
  // This ensures proper login page navigation when guest users want to authenticate.

  SolidAuthHandler.instance.configure(
    SolidAuthConfig(
      appTitle: appTitle,
      appDirectory: 'geopod',
      defaultServerUrl: 'https://pods.solidcommunity.au',
      appImage: const AssetImage('assets/images/app_image.png'),
      appLogo: const AssetImage('assets/images/app_icon.png'),
      loginSuccessWidget: appScaffold,

      // Clear security key on logout to ensure clean state.
      onSecurityKeyReset: () async {
        await KeyManager.clear();
        debugPrint('GeoPod: Security key cleared on logout');
      },
    ),
  );

  if (isDesktop) {
    await windowManager.ensureInitialized();
    const windowOptions = WindowOptions(title: appTitle);
    await windowManager.waitUntilReadyToShow(windowOptions, () async {});
  }

  // The runApp() function takes the given Widget and makes it the root of the
  // widget tree.

  runApp(const App());
}