fix: 使用 CommunityToolkit.Mvvm
This commit is contained in:
@@ -1,77 +1,45 @@
|
||||
using CloudPrint.Client.Infrastructure;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace CloudPrint.Client.Models;
|
||||
|
||||
public sealed class ClientSettings : ObservableObject
|
||||
public sealed partial class ClientSettings : ObservableObject
|
||||
{
|
||||
private string _serverAddress = "http://localhost:8080";
|
||||
private string _apiKey = string.Empty;
|
||||
private string _adminUsername = string.Empty;
|
||||
private string _adminAccessToken = string.Empty;
|
||||
private string _storeName = "默认打印店";
|
||||
private bool _allowInsecureGrpc = true;
|
||||
private string _libraryRoot = string.Empty;
|
||||
private string _printCacheRoot = string.Empty;
|
||||
private int _maxUploadSizeMb = 50;
|
||||
private int _heartbeatIntervalSeconds = 15;
|
||||
[ObservableProperty]
|
||||
private string serverAddress = "http://localhost:8080";
|
||||
|
||||
public string ServerAddress
|
||||
{
|
||||
get => _serverAddress;
|
||||
set => SetProperty(ref _serverAddress, value);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string apiKey = string.Empty;
|
||||
|
||||
public string ApiKey
|
||||
{
|
||||
get => _apiKey;
|
||||
set => SetProperty(ref _apiKey, value);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string adminUsername = string.Empty;
|
||||
|
||||
public string AdminUsername
|
||||
{
|
||||
get => _adminUsername;
|
||||
set => SetProperty(ref _adminUsername, value);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string adminAccessToken = string.Empty;
|
||||
|
||||
public string AdminAccessToken
|
||||
{
|
||||
get => _adminAccessToken;
|
||||
set => SetProperty(ref _adminAccessToken, value);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string storeName = "默认打印店";
|
||||
|
||||
public string StoreName
|
||||
{
|
||||
get => _storeName;
|
||||
set => SetProperty(ref _storeName, value);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private bool allowInsecureGrpc = true;
|
||||
|
||||
public bool AllowInsecureGrpc
|
||||
{
|
||||
get => _allowInsecureGrpc;
|
||||
set => SetProperty(ref _allowInsecureGrpc, value);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string libraryRoot = string.Empty;
|
||||
|
||||
public string LibraryRoot
|
||||
{
|
||||
get => _libraryRoot;
|
||||
set => SetProperty(ref _libraryRoot, value);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string printCacheRoot = string.Empty;
|
||||
|
||||
public string PrintCacheRoot
|
||||
{
|
||||
get => _printCacheRoot;
|
||||
set => SetProperty(ref _printCacheRoot, value);
|
||||
}
|
||||
private int maxUploadSizeMb = 50;
|
||||
private int heartbeatIntervalSeconds = 15;
|
||||
|
||||
public int MaxUploadSizeMb
|
||||
{
|
||||
get => _maxUploadSizeMb;
|
||||
set => SetProperty(ref _maxUploadSizeMb, Math.Clamp(value, 1, 1024));
|
||||
get => maxUploadSizeMb;
|
||||
set => SetProperty(ref maxUploadSizeMb, Math.Clamp(value, 1, 1024));
|
||||
}
|
||||
|
||||
public int HeartbeatIntervalSeconds
|
||||
{
|
||||
get => _heartbeatIntervalSeconds;
|
||||
set => SetProperty(ref _heartbeatIntervalSeconds, Math.Clamp(value, 5, 300));
|
||||
get => heartbeatIntervalSeconds;
|
||||
set => SetProperty(ref heartbeatIntervalSeconds, Math.Clamp(value, 5, 300));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
using CloudPrint.Client.Infrastructure;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace CloudPrint.Client.Models;
|
||||
|
||||
public sealed class CloudPrintDocument : ObservableObject
|
||||
public sealed partial class CloudPrintDocument : ObservableObject
|
||||
{
|
||||
private string _title = string.Empty;
|
||||
private string _description = string.Empty;
|
||||
private string _categoryName = "未分类";
|
||||
private bool _isUploaded;
|
||||
private string _syncStatus = "本地";
|
||||
[ObservableProperty]
|
||||
private string title = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string description = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string categoryName = "未分类";
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isUploaded;
|
||||
|
||||
[ObservableProperty]
|
||||
private string syncStatus = "本地";
|
||||
|
||||
public int Id { get; init; }
|
||||
public string FileName { get; init; } = string.Empty;
|
||||
@@ -21,36 +30,6 @@ public sealed class CloudPrintDocument : ObservableObject
|
||||
public int PageCount { get; init; }
|
||||
public DateTime CreatedAt { get; init; } = DateTime.Now;
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => _description;
|
||||
set => SetProperty(ref _description, value);
|
||||
}
|
||||
|
||||
public string CategoryName
|
||||
{
|
||||
get => _categoryName;
|
||||
set => SetProperty(ref _categoryName, value);
|
||||
}
|
||||
|
||||
public bool IsUploaded
|
||||
{
|
||||
get => _isUploaded;
|
||||
set => SetProperty(ref _isUploaded, value);
|
||||
}
|
||||
|
||||
public string SyncStatus
|
||||
{
|
||||
get => _syncStatus;
|
||||
set => SetProperty(ref _syncStatus, value);
|
||||
}
|
||||
|
||||
public string FileSizeText
|
||||
{
|
||||
get
|
||||
@@ -68,4 +47,4 @@ public sealed class CloudPrintDocument : ObservableObject
|
||||
return $"{FileSize} B";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using CloudPrint.Client.Infrastructure;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace CloudPrint.Client.Models;
|
||||
|
||||
@@ -11,13 +11,22 @@ public enum PrintJobStatus
|
||||
Cancelled
|
||||
}
|
||||
|
||||
public sealed class PrintJob : ObservableObject
|
||||
public sealed partial class PrintJob : ObservableObject
|
||||
{
|
||||
private PrintJobStatus _status = PrintJobStatus.Pending;
|
||||
private int _progress;
|
||||
private string _errorMessage = string.Empty;
|
||||
private int? _windowsJobId;
|
||||
private string _windowsJobStatus = string.Empty;
|
||||
[ObservableProperty]
|
||||
private int? windowsJobId;
|
||||
|
||||
[ObservableProperty]
|
||||
private string windowsJobStatus = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(StatusText))]
|
||||
private PrintJobStatus status = PrintJobStatus.Pending;
|
||||
|
||||
[ObservableProperty]
|
||||
private string errorMessage = string.Empty;
|
||||
|
||||
private int progress;
|
||||
|
||||
public int Id { get; init; }
|
||||
public string JobNo { get; init; } = string.Empty;
|
||||
@@ -34,40 +43,10 @@ public sealed class PrintJob : ObservableObject
|
||||
public DateTime? StartedAt { get; set; }
|
||||
public DateTime? CompletedAt { get; set; }
|
||||
|
||||
public int? WindowsJobId
|
||||
{
|
||||
get => _windowsJobId;
|
||||
set => SetProperty(ref _windowsJobId, value);
|
||||
}
|
||||
|
||||
public string WindowsJobStatus
|
||||
{
|
||||
get => _windowsJobStatus;
|
||||
set => SetProperty(ref _windowsJobStatus, value);
|
||||
}
|
||||
|
||||
public PrintJobStatus Status
|
||||
{
|
||||
get => _status;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _status, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(StatusText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Progress
|
||||
{
|
||||
get => _progress;
|
||||
set => SetProperty(ref _progress, Math.Clamp(value, 0, 100));
|
||||
}
|
||||
|
||||
public string ErrorMessage
|
||||
{
|
||||
get => _errorMessage;
|
||||
set => SetProperty(ref _errorMessage, value);
|
||||
get => progress;
|
||||
set => SetProperty(ref progress, Math.Clamp(value, 0, 100));
|
||||
}
|
||||
|
||||
public string StatusText => Status switch
|
||||
@@ -107,4 +86,4 @@ public sealed class PrintJob : ObservableObject
|
||||
Status = PrintJobStatus.Cancelled;
|
||||
CompletedAt = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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})";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user