From e37c01b4d7788c317c923695953165def1c987ef Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Tue, 17 Sep 2024 16:50:30 -0700 Subject: [PATCH] untested round robin --- lib/entities/background_tasks.dart | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/entities/background_tasks.dart b/lib/entities/background_tasks.dart index cfe0975af..d75fb9d0e 100644 --- a/lib/entities/background_tasks.dart +++ b/lib/entities/background_tasks.dart @@ -162,7 +162,7 @@ Future onStart(ServiceInstance service) async { final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name); final node = settingsStore.getCurrentNode(moneroWallets[i].type); wallet.connectToNode(node: node); - wallet.startSync(); + wallet.stopSync(); syncingWallets.add(wallet); } @@ -178,6 +178,7 @@ Future onStart(ServiceInstance service) async { final wallet = await walletLoadingService.load(firstWallet.type, firstWallet.name); final node = settingsStore.getCurrentNode(WalletType.litecoin); wallet.connectToNode(node: node); + wallet.stopSync(); // calling start sync isn't necessary since it's called after connecting to the node syncingWallets.add(wallet); } catch (e) { @@ -207,6 +208,8 @@ Future onStart(ServiceInstance service) async { continue; } + wallet.stopSync(); + syncingWallets.add(wallet); } catch (e) { print("error syncing bitcoin wallet_$i: $e"); @@ -214,16 +217,26 @@ Future onStart(ServiceInstance service) async { } print("STARTING SYNC TIMER"); + int currentSyncingWallet = 0; _syncTimer?.cancel(); + if (syncingWallets.isEmpty) return; + syncingWallets.first!.startSync(); _syncTimer = Timer.periodic(const Duration(milliseconds: 2000), (timer) { - if (syncingWallets.isEmpty) { - return; - } - for (int i = 0; i < syncingWallets.length; i++) { final wallet = syncingWallets[i]; if (wallet == null) continue; + if (wallet.syncStatus.progress() > 0.99) { + print("WALLET $i SYNCED"); + wallet.stopSync(); + currentSyncingWallet++; + if (currentSyncingWallet < syncingWallets.length) { + syncingWallets[currentSyncingWallet]!.startSync(); + } else { + currentSyncingWallet = 0; + } + } + final syncProgress = ((wallet.syncStatus.progress()) * 100).toStringAsPrecision(5); String prefix = walletTypeToCryptoCurrency(wallet.type).title; @@ -254,6 +267,10 @@ Future onStart(ServiceInstance service) async { } content += " - ${DateTime.now().toIso8601String()}"; + if (i != currentSyncingWallet) { + content = "${syncProgress}% PAUSED - Waiting for other wallets to finish"; + } + flutterLocalNotificationsPlugin.show( notificationId + i, title,