Files
UFL/ViewModels/MainWindowViewModel.cs

120 lines
3.3 KiB
C#
Raw Permalink Normal View History

2025-12-17 15:34:34 -07:00
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using UnifiedFarmLauncher.Models;
using UnifiedFarmLauncher.Services;
namespace UnifiedFarmLauncher.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
private readonly ConfigService _configService;
private WorkerConfig? _selectedWorker;
private string _statusText = "Ready";
private string _selectedWorkerType = "All";
2025-12-17 16:46:35 -07:00
private string _operationMode = "sheepit"; // "sheepit" or "flamenco"
2025-12-17 15:34:34 -07:00
public MainWindowViewModel()
{
_configService = new ConfigService();
Workers = new ObservableCollection<WorkerConfig>();
LoadWorkers();
}
public ObservableCollection<WorkerConfig> Workers { get; }
public WorkerConfig? SelectedWorker
{
get => _selectedWorker;
set
{
if (SetAndRaise(ref _selectedWorker, value))
{
UpdateStatusText();
}
}
}
public string StatusText
{
get => _statusText;
set => SetAndRaise(ref _statusText, value);
}
public string SelectedWorkerType
{
get => _selectedWorkerType;
set
{
if (SetAndRaise(ref _selectedWorkerType, value))
{
LoadWorkers();
}
}
}
2025-12-17 16:46:35 -07:00
public string OperationMode
{
get => _operationMode;
set
{
if (SetAndRaise(ref _operationMode, value))
{
// Notify that dependent properties also changed
OnPropertyChanged(nameof(OperationModeDisplayName));
OnPropertyChanged(nameof(OperationModeIcon));
}
}
}
public string OperationModeDisplayName => OperationMode == "sheepit" ? "SheepIt" : "Flamenco";
public string OperationModeIcon => OperationMode == "sheepit" ? "🐑" : "🔥";
2025-12-17 15:34:34 -07:00
public void LoadWorkers()
{
2025-12-17 16:25:49 -07:00
_configService.Reload();
2025-12-17 15:34:34 -07:00
var config = _configService.Load();
Workers.Clear();
var workers = config.Workers;
if (SelectedWorkerType != "All")
{
workers = workers.Where(w =>
{
if (SelectedWorkerType == "SheepIt")
return w.WorkerTypes.SheepIt != null;
if (SelectedWorkerType == "Flamenco")
return w.WorkerTypes.Flamenco != null;
return true;
}).ToList();
}
foreach (var worker in workers)
{
Workers.Add(worker);
}
UpdateStatusText();
}
private void UpdateStatusText()
{
if (SelectedWorker == null)
{
StatusText = $"Total workers: {Workers.Count}";
}
else
{
StatusText = $"Selected: {SelectedWorker.Name} ({SelectedWorker.Ssh.Host}:{SelectedWorker.Ssh.Port})";
}
}
public void RefreshWorkers()
{
LoadWorkers();
}
}
}