initialize method

Future<void> initialize()

Initialize the manager

Implementation

Future<void> initialize() async {
  try {
    _updateState(_state.copyWith(isLoading: true, errorMessage: ''));

    // Check if playerctl is installed
    final installed = await _service.isPlayerctlInstalled();
    _updateState(_state.copyWith(isPlayerctlInstalled: installed));

    if (!installed) {
      _updateState(
        _state.copyWith(
          errorMessage:
              'playerctl is not installed on this system.\n'
              'Please install it using:\n'
              'sudo apt install playerctl (Debian/Ubuntu)\n'
              'sudo pacman -S playerctl (Arch)\n'
              'sudo dnf install playerctl (Fedora)',
          isLoading: false,
        ),
      );
      return;
    }

    // Get playerctl version for debugging
    final version = await _service.getPlayerctlVersion();
    PlayerctlLogger.info('Playerctl version: $version', 'Init');

    // Check for active players
    await refreshPlayerList();

    // Start listening if we have active players
    if (_state.hasActivePlayer) {
      startListening();
      await updateCurrentVolume();
      await updateShuffleStatus();
      await updateLoopStatus();
      _startVolumeSync();
      _startMetadataRefresh();
    }

    // Start periodic player check (every 5 seconds)
    _startPlayerCheck();

    _updateState(_state.copyWith(isLoading: false));
  } catch (e) {
    _updateState(
      _state.copyWith(
        errorMessage: 'Error initializing: $e',
        isLoading: false,
      ),
    );
  }
}