47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
namespace ClawdDotNet.Desktop.ViewModels;
|
|
|
|
/// <summary>Eingabe eines Lizenzschlüssels. Siehe <c>AvaloniaLicensePrompt</c>.</summary>
|
|
public sealed partial class LicenseViewModel : ViewModelBase
|
|
{
|
|
private readonly TaskCompletionSource<string?> _completion = new();
|
|
|
|
[ObservableProperty]
|
|
private string _key;
|
|
|
|
public string HardwareId { get; }
|
|
|
|
/// <summary>Warum der bisherige Schlüssel nicht taugt; leer beim ersten Fragen.</summary>
|
|
public string Problem { get; }
|
|
|
|
/// <summary>Der eingegebene Schlüssel, oder <c>null</c> bei Abbruch.</summary>
|
|
public Task<string?> Result => _completion.Task;
|
|
|
|
public LicenseViewModel(string hardwareId, string? problem, string? currentKey)
|
|
{
|
|
HardwareId = hardwareId;
|
|
Problem = problem ?? "";
|
|
_key = currentKey ?? "";
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void Confirm()
|
|
{
|
|
var value = Key.Trim();
|
|
|
|
// Leere Eingabe ist kein Abbruch — sonst schließt sich das Fenster, wenn jemand
|
|
// versehentlich die Eingabetaste drückt.
|
|
if (value.Length == 0) return;
|
|
|
|
_completion.TrySetResult(value);
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void Cancel() => _completion.TrySetResult(null);
|
|
|
|
/// <summary>Schließt der Benutzer das Fenster, gilt das als Abbruch.</summary>
|
|
public void CancelIfPending() => _completion.TrySetResult(null);
|
|
}
|