From f55624090ac5fb7a55c8f48ae8a60d0bd5ad73d4 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 29 Aug 2026 14:51:27 +0200 Subject: [PATCH] Name the connected server in the sync diagnostics --- lib/core/widgets/about.dart | 5 +---- lib/database/powersync/powersync.dart | 10 ++++++++++ lib/powersync/sync_diagnostics.dart | 9 ++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/core/widgets/about.dart b/lib/core/widgets/about.dart index 0339481b6..e81a59817 100644 --- a/lib/core/widgets/about.dart +++ b/lib/core/widgets/about.dart @@ -28,7 +28,6 @@ import 'package:wger/core/logs.dart'; import 'package:wger/core/misc.dart'; import 'package:wger/core/network/auth_notifier.dart'; import 'package:wger/core/network/network_provider.dart'; -import 'package:wger/core/network/wger_base.dart'; import 'package:wger/core/wide_screen_wrapper.dart'; import 'package:wger/features/exercises/screens/add_exercise_screen.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; @@ -128,9 +127,7 @@ class AboutPage extends ConsumerWidget { onTap: () async { final url = buildGithubIssueUrl( applicationLogs: InMemoryLogStore().getFormattedLogs(), - syncDiagnostics: await collectSyncDiagnostics( - serverUrl: ref.read(wgerBaseProvider).serverUrl, - ), + syncDiagnostics: await collectSyncDiagnostics(), appVersion: await collectAppVersion(), serverVersion: authState?.serverVersion, ); diff --git a/lib/database/powersync/powersync.dart b/lib/database/powersync/powersync.dart index 92d20d2dd..64d9b3418 100644 --- a/lib/database/powersync/powersync.dart +++ b/lib/database/powersync/powersync.dart @@ -65,6 +65,15 @@ PowerSyncDatabase? _builtInstance; /// those paths need. PowerSyncDatabase? get builtPowerSyncInstance => _builtInstance; +String? _connectedServerUrl; + +/// The server the sync was last connected to, null before the first connect. +/// +/// What the sync diagnostics name as the backend: a report has to say where +/// the rejected uploads went, and it is written from paths that have no `ref` +/// to read the auth state with. +String? get connectedServerUrl => _connectedServerUrl; + /// Watches the sync status for a stream that keeps reconnecting without ever /// delivering data (e.g. blocked by a VPN or firewall) and flags it, see /// [SyncStreamWatchdog]. Fed from the DB's status stream by @@ -251,6 +260,7 @@ void connectPowerSync( required String reason, }) { _logger.info('Connecting to the sync service ($reason)'); + _connectedServerUrl = baseUrl; db.connect( connector: DjangoConnector( baseUrl: baseUrl, diff --git a/lib/powersync/sync_diagnostics.dart b/lib/powersync/sync_diagnostics.dart index d558aa019..45bff33a4 100644 --- a/lib/powersync/sync_diagnostics.dart +++ b/lib/powersync/sync_diagnostics.dart @@ -21,7 +21,8 @@ import 'package:logging/logging.dart'; import 'package:powersync/powersync.dart' show CredentialsException, PowerSyncProtocolException, SyncResponseException, SyncStatus; import 'package:wger/core/consts.dart'; -import 'package:wger/database/powersync/powersync.dart' show builtPowerSyncInstance; +import 'package:wger/database/powersync/powersync.dart' + show builtPowerSyncInstance, connectedServerUrl; import 'package:wger/powersync/connector.dart' show NoPowerSyncEndpointException, RetryableUploadException; @@ -208,7 +209,7 @@ Future collectLocalSyncState() async { /// Never throws: this runs on report paths where the app may already be in /// a broken state (e.g. the DB is closing down), and a missing sync section /// must not prevent the report itself. -Future collectSyncDiagnostics({String? serverUrl}) async { +Future collectSyncDiagnostics() async { final db = builtPowerSyncInstance; if (db == null) { return null; @@ -218,7 +219,9 @@ Future collectSyncDiagnostics({String? serverUrl}) async { return formatSyncDiagnostics( db.currentStatus, pendingUploads: queue.count, - server: serverCategory(serverUrl), + // The server this sync actually runs against, rather than one the + // caller happens to know: the counters below describe that connection + server: serverCategory(connectedServerUrl), local: await collectLocalSyncState(), ); } catch (e, s) {