Skip to content

Commit 9dbb621

Browse files
authored
fix pull ab twice in log (rustdesk#11699)
The reason for calling `pullAb` twice is that when `pullAb` is called for the first time, `setCurrentName` is also called. In `setCurrentName`, if the current address book has not been initialized, it will also attempt to pull. Because `quiet` is false during the first call and `setCurrentName` is not `await` synchronously, the `abLoading` can prevent the two calls. However, `abLoading` depends on `quiet`, so we need to add a new variable `_abLoadingLock`. Signed-off-by: 21pages <sunboeasy@gmail.com>
1 parent 1a8e300 commit 9dbb621

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

flutter/lib/models/ab_model.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,10 @@ abstract class BaseAb {
775775

776776
final pullError = "".obs;
777777
final pushError = "".obs;
778-
final abLoading = false.obs;
778+
final abLoading = false
779+
.obs; // Indicates whether the UI should show a loading state for the address book.
780+
var abPulling =
781+
false; // Tracks whether a pull operation is currently in progress to prevent concurrent pulls. Unlike abLoading, this is not tied to UI updates.
779782
bool initialized = false;
780783

781784
String name();
@@ -790,17 +793,22 @@ abstract class BaseAb {
790793
}
791794

792795
Future<void> pullAb({quiet = false}) async {
793-
debugPrint("pull ab \"${name()}\"");
794-
if (abLoading.value) return;
796+
if (abPulling) return;
797+
abPulling = true;
795798
if (!quiet) {
796799
abLoading.value = true;
797800
pullError.value = "";
798801
}
799802
initialized = false;
803+
debugPrint("pull ab \"${name()}\"");
800804
try {
801805
initialized = await pullAbImpl(quiet: quiet);
802-
} catch (_) {}
803-
abLoading.value = false;
806+
} catch (e) {
807+
debugPrint("Error occurred while pulling address book: $e");
808+
} finally {
809+
abLoading.value = false;
810+
abPulling = false;
811+
}
804812
}
805813

806814
Future<bool> pullAbImpl({quiet = false});

0 commit comments

Comments
 (0)