From a8a97f09b7287844009f3bd5b5aa2250fecf83c8 Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Fri, 12 Jun 2026 09:43:59 +0200 Subject: [PATCH] feat(app): connect to server before wallet open, status in bottom bar - ConnectAndSync() no longer bails early when no wallet is open: connection is established immediately after the wizard completes (Electrum-style), sync starts only once an account is available - KeepAlive tick no longer requires IsWalletOpen so the connection is maintained and auto-reconnected at all times - WalletSynchronizer is lazily created on first sync (not on connect) to avoid a null-ref guard on _synchronizer - Connection status indicator (dot + text) moved from wallet header to the status bar (always visible); tapping it still opens the server settings overlay - Menu "Rete" removed: Discover and ResetCerts are inside the server settings overlay; redundant top-level menu entry eliminated - "Server" button in settings overlay is no longer gated on IsWalletOpen --- src/App/ViewModels/MainWindowViewModel.cs | 25 +++++++--- src/App/Views/MainWindow.axaml | 60 +++++++++++------------ 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/App/ViewModels/MainWindowViewModel.cs b/src/App/ViewModels/MainWindowViewModel.cs index 8c16b02..f3ace12 100644 --- a/src/App/ViewModels/MainWindowViewModel.cs +++ b/src/App/ViewModels/MainWindowViewModel.cs @@ -397,7 +397,9 @@ public partial class MainWindowViewModel : ViewModelBase private async Task KeepAliveTickAsync() { - if (!IsWalletOpen || IsSyncing) + // Vale anche senza wallet aperto: se l'utente si è connesso dalle + // impostazioni server, la connessione va mantenuta e riconnessa. + if (IsSyncing) return; if (_client is { IsConnected: true }) { @@ -461,6 +463,9 @@ public partial class MainWindowViewModel : ViewModelBase ? Loc.Tr("msg.welcome.existing") : Loc.Tr("msg.welcome.new"); RefreshServers(); + // Come Electrum: ci si connette al server già durante il setup, senza + // aspettare l'apertura di un wallet (la sync parte poi all'apertura). + _ = ConnectAndSync(); } private void RefreshServers() @@ -776,8 +781,6 @@ public partial class MainWindowViewModel : ViewModelBase [RelayCommand] private async Task ConnectAndSync() { - if (_account is null || _doc is null) - return; if (IsSyncing) { _resyncRequested = true; @@ -812,8 +815,18 @@ public partial class MainWindowViewModel : ViewModelBase IsConnected = true; _autoReconnect = true; ConnectionStatus = $"{Loc.Tr("conn.connectedto")} {host}:{port}{(UseSsl ? " (TLS)" : "")}"; - // Synchronizer per connessione: conserva la cache di tx e - // prove verificate, così le risincronizzazioni sono incrementali. + } + + // Senza un wallet aperto ci si limita a stabilire/verificare la + // connessione: la sincronizzazione richiede un account. + if (_account is null || _doc is null) + return; + + // Synchronizer legato all'account corrente, creato alla prima sync + // dopo la connessione: conserva la cache di tx e prove verificate, + // così le risincronizzazioni sono incrementali. + if (_synchronizer is null) + { _synchronizer = new WalletSynchronizer(_account, _client, _doc.GapLimit); _synchronizer.Progress += msg => Dispatcher.UIThread.Post(() => StatusMessage = msg); } @@ -823,7 +836,7 @@ public partial class MainWindowViewModel : ViewModelBase do { _resyncRequested = false; - var result = await _synchronizer!.SyncOnceAsync(); + var result = await _synchronizer.SyncOnceAsync(); _lastTransactions = result.Transactions; _doc.Cache = new SyncCache diff --git a/src/App/Views/MainWindow.axaml b/src/App/Views/MainWindow.axaml index 91da29a..d3a45e5 100644 --- a/src/App/Views/MainWindow.axaml +++ b/src/App/Views/MainWindow.axaml @@ -26,10 +26,6 @@ - - - - @@ -159,29 +155,13 @@ - - - - - - - - - - - - - - + + + + + + @@ -331,10 +311,27 @@ - + - + + + + + + + + @@ -540,11 +537,10 @@ - +