Add IndefiniteRetryPolicy for WithAutomaticReconnect, wrap initial
StartAsync in a retry loop so the UI keeps retrying when Worker is
offline at startup, and expose IsReconnecting to StatusBar
("Connecting..." / "Online" / "Offline").
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System.Collections.Specialized;
|
|
using ClaudeDo.Ui.Services;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
namespace ClaudeDo.Ui.ViewModels;
|
|
|
|
public partial class StatusBarViewModel : ViewModelBase
|
|
{
|
|
private readonly WorkerClient _worker;
|
|
|
|
[ObservableProperty] private string _connectionStatus = "Offline";
|
|
[ObservableProperty] private string _activeTasksSummary = "";
|
|
[ObservableProperty] private string _statusMessage = "";
|
|
|
|
public StatusBarViewModel(WorkerClient worker)
|
|
{
|
|
_worker = worker;
|
|
|
|
worker.PropertyChanged += (_, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(WorkerClient.IsConnected) ||
|
|
e.PropertyName == nameof(WorkerClient.IsReconnecting))
|
|
{
|
|
ConnectionStatus = worker.IsConnected ? "Online"
|
|
: worker.IsReconnecting ? "Connecting..."
|
|
: "Offline";
|
|
}
|
|
};
|
|
|
|
worker.ActiveTasks.CollectionChanged += OnActiveTasksChanged;
|
|
RefreshActiveSummary();
|
|
}
|
|
|
|
private void OnActiveTasksChanged(object? sender, NotifyCollectionChangedEventArgs e) =>
|
|
RefreshActiveSummary();
|
|
|
|
private void RefreshActiveSummary()
|
|
{
|
|
if (_worker.ActiveTasks.Count == 0)
|
|
{
|
|
ActiveTasksSummary = "";
|
|
return;
|
|
}
|
|
|
|
var parts = _worker.ActiveTasks
|
|
.Select(t => $"{t.Slot}: {Shorten(t.TaskId)}")
|
|
.ToList();
|
|
ActiveTasksSummary = string.Join(" | ", parts);
|
|
}
|
|
|
|
private static string Shorten(string id) =>
|
|
id.Length > 8 ? id[..8] : id;
|
|
|
|
public void ShowMessage(string msg) => StatusMessage = msg;
|
|
}
|