handleLifecycleChange method

Future<void> handleLifecycleChange(
  1. NodeLifecycleState state
)

Processes a change in application lifecycle state.

Implementation

Future<void> handleLifecycleChange(NodeLifecycleState state) async {
  _logger.info('Lifecycle state changed to: $state');
  _currentLifecycleState = state;

  switch (state) {
    case NodeLifecycleState.resumed:
      final target = _isLowBattery
          ? IpfsPowerMode.lowPower
          : IpfsPowerMode.fullActive;
      await transitionTo(target);
    case NodeLifecycleState.inactive:
      _logger.debug(
        'Application inactive; maintaining mode $_currentPowerMode',
      );
    case NodeLifecycleState.paused:
      if (requestBackgroundExtensionOnPause) {
        try {
          await adapter.requestBackgroundExtension(
            duration: backgroundExtensionDuration,
          );
        } catch (e) {
          _logger.warning(
            'Failed to request background execution extension: $e',
          );
        }
      }
      await transitionTo(IpfsPowerMode.suspendedMesh);
    case NodeLifecycleState.detached:
      _logger.warning('Application detached. Executing shutdown handler...');
      await transitionTo(IpfsPowerMode.suspendedMesh);
      if (onDetached != null) {
        try {
          await onDetached!();
        } catch (e, st) {
          _logger.error('Error executing onDetached callback', e, st);
        }
      }
  }
}