Files
sharedinbox/lib/core/models/user_preferences.dart
T
Thomas SharedInboxandClaude Sonnet 4.6 49fdf83834 feat: pre-fetch email bodies for offline access (#373)
Adds a background body-prefetch mechanism with network-awareness and a
user-configurable cache size limit to keep email bodies available offline
without downloading the entire mailbox.

- Schema v38: adds `prefetch_mode` and `body_cache_limit_mb` columns to
  `user_preferences` (defaults: wifiOnly / 100 MB).
- `PrefetchMode` enum (disabled / wifiOnly / always) in the model.
- `BodyCacheService`: fetches bodies for uncached emails (newest first,
  batch of 20), evicts oldest cached bodies when the size limit is
  exceeded.
- Registers a separate WorkManager periodic task (`si_bg_prefetch`) with
  `NetworkType.unmetered` (Wi-Fi only) or `NetworkType.connected` (any)
  based on the stored preference; cancels the task when disabled.
- On app startup, reads the stored preference and re-registers the task
  with the correct constraint.
- Preferences screen: radio group for prefetch mode + dropdown for
  cache size limit (50 / 100 / 200 / 500 MB).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 03:29:03 +02:00

32 lines
821 B
Dart

enum MenuPosition { bottom, top }
enum AfterMailViewAction { nextMessage, showMailbox }
enum PrefetchMode {
disabled,
wifiOnly,
always;
static PrefetchMode fromString(String? value) {
return PrefetchMode.values.firstWhere(
(e) => e.name == value,
orElse: () => PrefetchMode.wifiOnly,
);
}
}
class UserPreferences {
const UserPreferences({
this.menuPosition = MenuPosition.bottom,
this.mailViewButtonPosition = MenuPosition.bottom,
this.afterMailViewAction = AfterMailViewAction.nextMessage,
this.prefetchMode = PrefetchMode.wifiOnly,
this.bodyCacheLimitMb = 100,
});
final MenuPosition menuPosition;
final MenuPosition mailViewButtonPosition;
final AfterMailViewAction afterMailViewAction;
final PrefetchMode prefetchMode;
final int bodyCacheLimitMb;
}