main function

Future<void> main()

Implementation

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  PipMode.initialize();

  try {
    mediaHandler = await AudioService.init(
      builder: _buildMediaHandler,
      config: const AudioServiceConfig(
        androidNotificationChannelId: 'com.github.damontecres.stash_app_flutter.channel.audio',
        androidNotificationChannelName: 'StashFlow Playback',
        androidNotificationOngoing: false,
        androidStopForegroundOnPause: true,
      ),    );
  } catch (e) {
    debugPrint('Failed to initialize AudioService: $e');
    // Fallback or handle gracefully
  }

  final sharedPreferences = await SharedPreferences.getInstance();

  final oldDebugPrint = debugPrint;
  debugPrint = (String? message, {int? wrapWidth}) {
    if (message != null) {
      AppLogStore.instance.add(message, source: 'debugPrint');
    }
    oldDebugPrint(message, wrapWidth: wrapWidth);
  };

  FlutterError.onError = (FlutterErrorDetails details) {
    AppLogStore.instance.add(
      details.exceptionAsString(),
      source: 'flutter_error',
    );
    FlutterError.presentError(details);
  };

  PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
    AppLogStore.instance.add('$error\n$stack', source: 'unhandled_error');
    return false;
  };

  runApp(
    ProviderScope(
      overrides: [
        sharedPreferencesProvider.overrideWithValue(sharedPreferences),
      ],
      child: const MyApp(),
    ),
  );
}