getAppPreferences method

  1. @override
Future<Either<Failure, AppPreferences>> getAppPreferences()
override

Retrieves all app preferences

Implementation

@override
Future<Either<Failure, AppPreferences>> getAppPreferences() async {
  try {
    final prefsDto = await _isar.appPreferencesDtos.get(_prefsId);

    if (prefsDto == null) {
      // Fallback to legacy AppSettingsModel if exists (Migration)
      final legacySettings = await _isar.appSettingsModels.get(_settingsId);
      if (legacySettings != null) {
        return Right(legacySettings.toAppPreferences());
      }
      // Return default preferences if none exist
      return Right(AppPreferences.defaults());
    }

    return Right(prefsDto.toDomain());
  } catch (e) {
    return Left(CacheFailure("Failed to get app preferences: $e"));
  }
}