120 lines
3.3 KiB
C#
120 lines
3.3 KiB
C#
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";
|
|
private string _operationMode = "sheepit"; // "sheepit" or "flamenco"
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
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" ? "🐑" : "🔥";
|
|
|
|
public void LoadWorkers()
|
|
{
|
|
_configService.Reload();
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|