fix not saving cache after changing current address book (#7544)

and get address book mode from cache

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2024-03-28 20:50:53 +08:00 committed by GitHub
parent 0c32a889a9
commit 4b0e88ce46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,7 +53,7 @@ class AbModel {
RxString get currentAbPullError => current.pullError; RxString get currentAbPullError => current.pullError;
RxString get currentAbPushError => current.pushError; RxString get currentAbPushError => current.pushError;
String? _personalAbGuid; String? _personalAbGuid;
RxBool legacyMode = true.obs; RxBool legacyMode = false.obs;
final sortTags = shouldSortTags().obs; final sortTags = shouldSortTags().obs;
final filterByIntersection = filterAbTagByIntersection().obs; final filterByIntersection = filterAbTagByIntersection().obs;
@ -151,10 +151,7 @@ class AbModel {
// set current address book name // set current address book name
if (!listInitialized) { if (!listInitialized) {
listInitialized = true; listInitialized = true;
final name = bind.getLocalFlutterOption(k: 'current-ab-name'); trySetCurrentToLast();
if (addressbooks.containsKey(name)) {
_currentName.value = name;
}
} }
if (!addressbooks.containsKey(_currentName.value)) { if (!addressbooks.containsKey(_currentName.value)) {
setCurrentName(legacyMode.value setCurrentName(legacyMode.value
@ -551,6 +548,13 @@ class AbModel {
return res; return res;
} }
trySetCurrentToLast() {
final name = bind.getLocalFlutterOption(k: 'current-ab-name');
if (addressbooks.containsKey(name)) {
_currentName.value = name;
}
}
Future<void> loadCache() async { Future<void> loadCache() async {
try { try {
if (_cacheLoadOnceFlag || currentAbLoading.value) return; if (_cacheLoadOnceFlag || currentAbLoading.value) return;
@ -562,10 +566,8 @@ class AbModel {
final data = jsonDecode(cache); final data = jsonDecode(cache);
if (data == null || data['access_token'] != access_token) return; if (data == null || data['access_token'] != access_token) return;
_deserializeCache(data); _deserializeCache(data);
final name = bind.getLocalFlutterOption(k: 'current-ab-name'); legacyMode.value = addressbooks.containsKey(_legacyAddressBookName);
if (addressbooks.containsKey(name)) { trySetCurrentToLast();
_currentName.value = name;
}
} catch (e) { } catch (e) {
debugPrint("load ab cache: $e"); debugPrint("load ab cache: $e");
} }
@ -661,11 +663,11 @@ class AbModel {
} }
if (!current.initialized) { if (!current.initialized) {
await current.pullAb(quiet: false); await current.pullAb(quiet: false);
_saveCache();
} }
_refreshTab(); _refreshTab();
if (oldName != _currentName.value) { if (oldName != _currentName.value) {
_syncAllFromRecent = true; _syncAllFromRecent = true;
_saveCache();
} }
} }