From f15bad571560cb986f456e5ac5e5106b183aebdc Mon Sep 17 00:00:00 2001 From: Janez T Date: Thu, 23 Oct 2025 20:52:43 +0200 Subject: [PATCH] feat: Sync drawings on app startup after provider initialization --- lib/providers/app_provider.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/providers/app_provider.dart b/lib/providers/app_provider.dart index 2b2538a..a704fce 100644 --- a/lib/providers/app_provider.dart +++ b/lib/providers/app_provider.dart @@ -39,9 +39,27 @@ class AppProvider with ChangeNotifier { _initializeTileCache(); _initializeLocationTracking(); _loadSimpleMode(); + _syncDrawingsOnStartup(); // Sync drawings immediately after providers load _isInitialized = true; } + /// Sync drawings from messages on app startup (before BLE connection) + Future _syncDrawingsOnStartup() async { + // Wait for MessagesProvider to finish initializing + // DrawingProvider loads around the same time + int attempts = 0; + while (!messagesProvider.isInitialized && attempts < 20) { + await Future.delayed(const Duration(milliseconds: 50)); + attempts++; + } + + // Give DrawingProvider a moment to finish loading too + await Future.delayed(const Duration(milliseconds: 100)); + + debugPrint('🔄 [AppProvider] Early sync: syncing drawings from messages...'); + messagesProvider.syncDrawingsWithProvider(drawingProvider); + } + /// Load simple mode setting from shared preferences Future _loadSimpleMode() async { try {