initializeAirpassBackgroundService function

Future<void> initializeAirpassBackgroundService()

Initializes and configures the background service.

Call this once from main() before runApp().

Implementation

Future<void> initializeAirpassBackgroundService() async {
  _log('Initializing background service...');
  await NotificationHelper.initialize();
  final service = FlutterBackgroundService();

  try {
    if (await service.isRunning()) {
      _log('Background service is already running.');
      return;
    }
  } catch (e) {
    _log('Could not query background service state: $e');
  }

  await service.configure(
    androidConfiguration: AndroidConfiguration(
      onStart: _onServiceStart,
      autoStart: true,
      isForegroundMode: true,
      initialNotificationTitle: 'United Voices',
      initialNotificationContent: 'Mesh network is active',
      foregroundServiceNotificationId: 42,
      foregroundServiceTypes: [AndroidForegroundType.dataSync],
    ),
    iosConfiguration: IosConfiguration(
      autoStart: false,
      onForeground: _onServiceStart,
      onBackground: _onIosBackground,
    ),
  );
  _log('Background service configured successfully.');
}