worldhopper/lib/providers/sync_progress_provider.dart
Felipe M. 545638c86d
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
feat: report reading progress to OPDS server on page turns
Fire a GET request to the PSE page URL on each page turn so servers like
Kavita can track reading progress even when images are served from the
local cache. Uses ResponseType.stream and drains the body immediately to
avoid holding the full image in memory. Gated behind a new "Sync progress
for cached pages" setting (off by default) since it consumes additional
data. On book completion the last page is reported so the server marks
the book as read (covers both image and EPUB readers).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 23:58:25 +01:00

35 lines
1.1 KiB
Dart

import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:shared_preferences/shared_preferences.dart';
part 'sync_progress_provider.g.dart';
/// Key for storing the sync-progress-for-cached-pages preference.
const String _syncProgressKey = 'sync_progress_for_cached_pages';
/// Provider for the "Sync progress for cached pages" setting.
///
/// When enabled, the app fires a GET request for each page turn so the OPDS
/// server (e.g. Kavita) can track reading progress even when images are served
/// from the local cache. This uses additional data.
@riverpod
class SyncProgressNotifier extends _$SyncProgressNotifier {
@override
bool build() {
_load();
return false; // Default: off (saves data)
}
Future<void> _load() async {
final prefs = await SharedPreferences.getInstance();
final stored = prefs.getBool(_syncProgressKey);
if (stored != null) {
state = stored;
}
}
Future<void> setSyncProgress(bool enabled) async {
state = enabled;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_syncProgressKey, enabled);
}
}