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,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));
}
}
}