feat(ui): persist last server and split connection status text
- AppConfig stores LastServerHost/Port/UseSsl; restored on next launch so the wallet reconnects to the last-used server instead of defaulting to the first bootstrap entry - Added ConnectionStatusShort for the status bar (short label only); ConnectionStatus retains the full "Connesso a ip:porta" shown in the server settings overlay
This commit is contained in:
@@ -46,6 +46,9 @@ public partial class MainWindowViewModel
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string connectionStatus = Loc.Tr("conn.none");
|
private string connectionStatus = Loc.Tr("conn.none");
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string connectionStatusShort = Loc.Tr("conn.none");
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isConnected;
|
private bool isConnected;
|
||||||
|
|
||||||
@@ -103,11 +106,24 @@ public partial class MainWindowViewModel
|
|||||||
KnownServers.Clear();
|
KnownServers.Clear();
|
||||||
foreach (var server in Registry.All)
|
foreach (var server in Registry.All)
|
||||||
KnownServers.Add(server);
|
KnownServers.Add(server);
|
||||||
SelectedKnownServer = KnownServers.FirstOrDefault();
|
|
||||||
if (SelectedKnownServer is null)
|
if (_config.LastServerHost is { Length: > 0 } savedHost && _config.LastServerPort is { } savedPort)
|
||||||
{
|
{
|
||||||
ServerHost = "127.0.0.1";
|
_syncingServerFields = true;
|
||||||
ServerPort = (UseSsl ? Profile.DefaultSslPort : Profile.DefaultTcpPort).ToString();
|
UseSsl = _config.LastServerUseSsl;
|
||||||
|
ServerHost = savedHost;
|
||||||
|
ServerPort = savedPort.ToString();
|
||||||
|
SelectedKnownServer = KnownServers.FirstOrDefault(s => s.Host == savedHost);
|
||||||
|
_syncingServerFields = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectedKnownServer = KnownServers.FirstOrDefault();
|
||||||
|
if (SelectedKnownServer is null)
|
||||||
|
{
|
||||||
|
ServerHost = "127.0.0.1";
|
||||||
|
ServerPort = (UseSsl ? Profile.DefaultSslPort : Profile.DefaultTcpPort).ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +195,7 @@ public partial class MainWindowViewModel
|
|||||||
foreach (var (h, p) in candidates)
|
foreach (var (h, p) in candidates)
|
||||||
{
|
{
|
||||||
ConnectionStatus = $"{Loc.Tr("conn.connectingto")} {h}:{p}…";
|
ConnectionStatus = $"{Loc.Tr("conn.connectingto")} {h}:{p}…";
|
||||||
|
ConnectionStatusShort = Loc.Tr("conn.connectingto") + "…";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var pins = new CertificatePinStore(AppPaths.CertificatePinsPath(Net));
|
var pins = new CertificatePinStore(AppPaths.CertificatePinsPath(Net));
|
||||||
@@ -188,10 +205,12 @@ public partial class MainWindowViewModel
|
|||||||
{
|
{
|
||||||
IsConnected = false;
|
IsConnected = false;
|
||||||
ConnectionStatus = Loc.Tr("conn.none");
|
ConnectionStatus = Loc.Tr("conn.none");
|
||||||
|
ConnectionStatusShort = Loc.Tr("conn.none");
|
||||||
});
|
});
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
_autoReconnect = true;
|
_autoReconnect = true;
|
||||||
ConnectionStatus = $"{Loc.Tr("conn.connectedto")} {h}:{p}";
|
ConnectionStatus = $"{Loc.Tr("conn.connectedto")} {h}:{p}";
|
||||||
|
ConnectionStatusShort = Loc.Tr("conn.connectedto");
|
||||||
// Update the UI to reflect the server actually connected.
|
// Update the UI to reflect the server actually connected.
|
||||||
_syncingServerFields = true;
|
_syncingServerFields = true;
|
||||||
ServerHost = h;
|
ServerHost = h;
|
||||||
@@ -199,6 +218,11 @@ public partial class MainWindowViewModel
|
|||||||
SelectedKnownServer = KnownServers.FirstOrDefault(s => s.Host == h)
|
SelectedKnownServer = KnownServers.FirstOrDefault(s => s.Host == h)
|
||||||
?? SelectedKnownServer;
|
?? SelectedKnownServer;
|
||||||
_syncingServerFields = false;
|
_syncingServerFields = false;
|
||||||
|
// Persist the last-used server so it is restored on next launch.
|
||||||
|
_config.LastServerHost = h;
|
||||||
|
_config.LastServerPort = p;
|
||||||
|
_config.LastServerUseSsl = UseSsl;
|
||||||
|
_config.Save();
|
||||||
lastError = null;
|
lastError = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -264,12 +288,14 @@ public partial class MainWindowViewModel
|
|||||||
{
|
{
|
||||||
IsConnected = false;
|
IsConnected = false;
|
||||||
ConnectionStatus = Loc.Tr("conn.none");
|
ConnectionStatus = Loc.Tr("conn.none");
|
||||||
|
ConnectionStatusShort = Loc.Tr("conn.none");
|
||||||
StatusMessage = ex.Message;
|
StatusMessage = ex.Message;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
IsConnected = _client?.IsConnected == true;
|
IsConnected = _client?.IsConnected == true;
|
||||||
ConnectionStatus = IsConnected ? ConnectionStatus : Loc.Tr("conn.none");
|
ConnectionStatus = IsConnected ? ConnectionStatus : Loc.Tr("conn.none");
|
||||||
|
ConnectionStatusShort = IsConnected ? Loc.Tr("conn.connectedto") : Loc.Tr("conn.none");
|
||||||
StatusMessage = $"Errore: {ex.Message}";
|
StatusMessage = $"Errore: {ex.Message}";
|
||||||
if (_account is not null)
|
if (_account is not null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -895,7 +895,7 @@
|
|||||||
IsVisible="{Binding IsConnected}"/>
|
IsVisible="{Binding IsConnected}"/>
|
||||||
<Ellipse Width="10" Height="10" Fill="{DynamicResource DangerBrush}" VerticalAlignment="Center"
|
<Ellipse Width="10" Height="10" Fill="{DynamicResource DangerBrush}" VerticalAlignment="Center"
|
||||||
IsVisible="{Binding !IsConnected}"/>
|
IsVisible="{Binding !IsConnected}"/>
|
||||||
<TextBlock Text="{Binding ConnectionStatus}" FontSize="12"
|
<TextBlock Text="{Binding ConnectionStatusShort}" FontSize="12"
|
||||||
Foreground="{DynamicResource SystemAccentColor}"
|
Foreground="{DynamicResource SystemAccentColor}"
|
||||||
VerticalAlignment="Center"/>
|
VerticalAlignment="Center"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ public sealed class AppConfig
|
|||||||
/// <summary>Display unit for amounts (see <see cref="Wallet.CoinAmount.Units"/>).</summary>
|
/// <summary>Display unit for amounts (see <see cref="Wallet.CoinAmount.Units"/>).</summary>
|
||||||
public string Unit { get; set; } = "PLM";
|
public string Unit { get; set; } = "PLM";
|
||||||
|
|
||||||
|
/// <summary>Last successfully connected server, persisted across sessions.</summary>
|
||||||
|
public string? LastServerHost { get; set; }
|
||||||
|
public int? LastServerPort { get; set; }
|
||||||
|
public bool LastServerUseSsl { get; set; } = true;
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
|
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
|
||||||
|
|
||||||
public static AppConfig Load(string? path = null)
|
public static AppConfig Load(string? path = null)
|
||||||
|
|||||||
Reference in New Issue
Block a user