fix: 使用 CommunityToolkit.Mvvm

This commit is contained in:
Shiqvlizi Name
2026-05-28 23:26:37 +08:00
parent 47572fefb8
commit ef61ae7e6b
12 changed files with 310 additions and 512 deletions

View File

@@ -1,4 +1,4 @@
using CloudPrint.Client.Infrastructure;
using CommunityToolkit.Mvvm.ComponentModel;
namespace CloudPrint.Client.Models;
@@ -11,11 +11,20 @@ public enum PrinterStatus
Unknown = 99
}
public sealed class PrinterInfo : ObservableObject
public sealed partial class PrinterInfo : ObservableObject
{
private PrinterStatus _status;
private int _queueCount;
private string _statusMessage = string.Empty;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(DisplayText))]
private int queueCount;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(DisplayText))]
private string statusMessage = string.Empty;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusText))]
[NotifyPropertyChangedFor(nameof(DisplayText))]
private PrinterStatus status;
public int Id { get; init; }
public string Name { get; init; } = string.Empty;
@@ -24,40 +33,11 @@ public sealed class PrinterInfo : ObservableObject
public string ApiKey { get; init; } = string.Empty;
public DateTime? LastHeartbeat { get; set; }
public int QueueCount
partial void OnQueueCountChanged(int value)
{
get => _queueCount;
set
if (value < 0)
{
if (SetProperty(ref _queueCount, Math.Max(0, value)))
{
OnPropertyChanged(nameof(DisplayText));
}
}
}
public string StatusMessage
{
get => _statusMessage;
set
{
if (SetProperty(ref _statusMessage, value))
{
OnPropertyChanged(nameof(DisplayText));
}
}
}
public PrinterStatus Status
{
get => _status;
set
{
if (SetProperty(ref _status, value))
{
OnPropertyChanged(nameof(StatusText));
OnPropertyChanged(nameof(DisplayText));
}
QueueCount = 0;
}
}
@@ -79,4 +59,4 @@ public sealed class PrinterInfo : ObservableObject
return $"{DisplayName}{StatusText}{queueText}{messageText}";
}
}
}
}