Skip to content

Commit

Permalink
fix not saving cache after changing current address book (#7544)
Browse files Browse the repository at this point in the history
and get address book mode from cache

Signed-off-by: 21pages <pages21@163.com>
  • Loading branch information
21pages committed Mar 28, 2024
1 parent 0c32a88 commit 4b0e88c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions flutter/lib/models/ab_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AbModel {
RxString get currentAbPullError => current.pullError;
RxString get currentAbPushError => current.pushError;
String? _personalAbGuid;
RxBool legacyMode = true.obs;
RxBool legacyMode = false.obs;

final sortTags = shouldSortTags().obs;
final filterByIntersection = filterAbTagByIntersection().obs;
Expand Down Expand Up @@ -151,10 +151,7 @@ class AbModel {
// set current address book name
if (!listInitialized) {
listInitialized = true;
final name = bind.getLocalFlutterOption(k: 'current-ab-name');
if (addressbooks.containsKey(name)) {
_currentName.value = name;
}
trySetCurrentToLast();
}
if (!addressbooks.containsKey(_currentName.value)) {
setCurrentName(legacyMode.value
Expand Down Expand Up @@ -551,6 +548,13 @@ class AbModel {
return res;
}

trySetCurrentToLast() {
final name = bind.getLocalFlutterOption(k: 'current-ab-name');
if (addressbooks.containsKey(name)) {
_currentName.value = name;
}
}

Future<void> loadCache() async {
try {
if (_cacheLoadOnceFlag || currentAbLoading.value) return;
Expand All @@ -562,10 +566,8 @@ class AbModel {
final data = jsonDecode(cache);
if (data == null || data['access_token'] != access_token) return;
_deserializeCache(data);
final name = bind.getLocalFlutterOption(k: 'current-ab-name');
if (addressbooks.containsKey(name)) {
_currentName.value = name;
}
legacyMode.value = addressbooks.containsKey(_legacyAddressBookName);
trySetCurrentToLast();
} catch (e) {
debugPrint("load ab cache: $e");
}
Expand Down Expand Up @@ -661,11 +663,11 @@ class AbModel {
}
if (!current.initialized) {
await current.pullAb(quiet: false);
_saveCache();
}
_refreshTab();
if (oldName != _currentName.value) {
_syncAllFromRecent = true;
_saveCache();
}
}

Expand Down

0 comments on commit 4b0e88c

Please sign in to comment.