add proper persistence expirations and collapse the connection section by default
This commit is contained in:
@@ -27,23 +27,41 @@ import 'package:weblibre/features/user/data/providers.dart';
|
||||
part 'persisted_bool.g.dart';
|
||||
|
||||
enum PersistedBoolKey {
|
||||
extensionsExpanded(key: 'ExtensionsExpanded', defaultValue: false),
|
||||
connectionsExpanded(key: 'ConnectionsExpanded', defaultValue: true),
|
||||
extensionsExpanded(
|
||||
key: 'ExtensionsExpanded',
|
||||
defaultValue: false,
|
||||
cacheTime: StorageCacheTime(Duration(days: 30)),
|
||||
),
|
||||
connectionsExpanded(
|
||||
key: 'ConnectionsExpanded',
|
||||
defaultValue: false,
|
||||
cacheTime: StorageCacheTime(Duration(days: 30)),
|
||||
),
|
||||
searchSuggestionsExpanded(
|
||||
key: 'SearchSuggestionsExpanded',
|
||||
defaultValue: true,
|
||||
cacheTime: StorageCacheTime(Duration(days: 30)),
|
||||
),
|
||||
infoboxExpanded(
|
||||
key: 'InfoboxExpanded',
|
||||
defaultValue: true,
|
||||
cacheTime: StorageCacheTime(Duration(days: 30)),
|
||||
),
|
||||
infoboxExpanded(key: 'InfoboxExpanded', defaultValue: true),
|
||||
tabSuggestions(key: 'TabSuggestions', defaultValue: false),
|
||||
supporterBannerDismissed(
|
||||
key: 'SupporterBannerDismissed',
|
||||
defaultValue: false,
|
||||
);
|
||||
|
||||
const PersistedBoolKey({required this.key, required this.defaultValue});
|
||||
const PersistedBoolKey({
|
||||
required this.key,
|
||||
required this.defaultValue,
|
||||
this.cacheTime = StorageCacheTime.unsafe_forever,
|
||||
});
|
||||
|
||||
final String key;
|
||||
final bool defaultValue;
|
||||
final StorageCacheTime cacheTime;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
@@ -58,6 +76,7 @@ class PersistedBool extends _$PersistedBool {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: key.key,
|
||||
options: StorageOptions(cacheTime: key.cacheTime),
|
||||
encode: (state) => jsonEncode([state]),
|
||||
decode: (encoded) => (jsonDecode(encoded) as List<dynamic>).first as bool,
|
||||
);
|
||||
|
||||
@@ -348,6 +348,7 @@ class PinnedAddonIds extends _$PinnedAddonIds {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'PinnedAddonIds',
|
||||
options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
|
||||
encode: (state) => jsonEncode(state.toList()),
|
||||
decode: (encoded) =>
|
||||
(jsonDecode(encoded) as List<dynamic>).cast<String>().toSet(),
|
||||
|
||||
+1
@@ -34,6 +34,7 @@ class BookmarkListUiStateNotifier extends _$BookmarkListUiStateNotifier {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'BookmarkListUiState',
|
||||
options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
|
||||
);
|
||||
|
||||
return stateOrNull ?? BookmarkListUiState();
|
||||
|
||||
+4
@@ -54,6 +54,7 @@ class TabsViewModeController extends _$TabsViewModeController {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'TabsViewMode',
|
||||
options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
|
||||
encode: (state) => jsonEncode([state.name]),
|
||||
decode: (encoded) {
|
||||
final name = (jsonDecode(encoded) as List<dynamic>).first as String;
|
||||
@@ -101,6 +102,9 @@ class TabViewFilterController extends _$TabViewFilterController {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'TabViewFilterOptions',
|
||||
options: const StorageOptions(
|
||||
cacheTime: StorageCacheTime(Duration(days: 7)),
|
||||
),
|
||||
);
|
||||
|
||||
return stateOrNull ?? TabViewFilterOptions.withDefaults();
|
||||
|
||||
@@ -61,6 +61,9 @@ class HistoryVisitsFilter extends _$HistoryVisitsFilter {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'HistoryVisitsFilterOptions',
|
||||
options: const StorageOptions(
|
||||
cacheTime: StorageCacheTime(Duration(days: 7)),
|
||||
),
|
||||
);
|
||||
|
||||
return stateOrNull ?? HistoryFilterOptions.withDefaults();
|
||||
@@ -86,6 +89,9 @@ class HistoryDownloadsFilter extends _$HistoryDownloadsFilter {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'HistoryDownloadsFilterOptions',
|
||||
options: const StorageOptions(
|
||||
cacheTime: StorageCacheTime(Duration(days: 7)),
|
||||
),
|
||||
);
|
||||
|
||||
return stateOrNull ??
|
||||
|
||||
+1
@@ -96,6 +96,7 @@ class SearchModuleOrder extends _$SearchModuleOrder {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: group.key,
|
||||
options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
|
||||
encode: (state) => jsonEncode(state.map((e) => e.toJson()).toList()),
|
||||
decode: (encoded) {
|
||||
final decoded = (jsonDecode(encoded) as List<dynamic>)
|
||||
|
||||
+1
@@ -90,6 +90,7 @@ class SelectedContainer extends _$SelectedContainer {
|
||||
final persistResult = persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'SelectedContainer',
|
||||
options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
|
||||
encode: (state) => jsonEncode([state]),
|
||||
decode: (encoded) =>
|
||||
(jsonDecode(encoded) as List<dynamic>).first as String?,
|
||||
|
||||
@@ -59,6 +59,7 @@ class WebSearchSettingsController extends _$WebSearchSettingsController {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'WebSearchSettings',
|
||||
options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
|
||||
);
|
||||
|
||||
return stateOrNull ?? WebSearchSettings.withDefaults();
|
||||
|
||||
+3
@@ -113,6 +113,9 @@ class SmallWebSessionController extends _$SmallWebSessionController {
|
||||
final persistFuture = persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'SmallWebSessionState',
|
||||
options: const StorageOptions(
|
||||
cacheTime: StorageCacheTime(Duration(days: 30)),
|
||||
),
|
||||
encode: (state) => jsonEncode(
|
||||
(state.value ?? SmallWebSessionState.initial(SmallWebSourceKind.kagi))
|
||||
.toJson(),
|
||||
|
||||
@@ -34,6 +34,7 @@ class BackupDirectoryUri extends _$BackupDirectoryUri {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: 'BackupDirectoryUri',
|
||||
options: const StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
|
||||
encode: (state) => state?.toString() ?? '',
|
||||
decode: (encoded) => encoded.isEmpty ? null : Uri.parse(encoded),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user