refactor: change constructors of multiple services to private access

This commit is contained in:
poli0981 committed 2026-10-15 13:16:40 +07:00
1 parent 42ce0547a2
commit 0b9e465d4e
7 files changed
+45 -12

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ public class ConfigurationService
private readonly SemaphoreSlim _saveLock = new(1, 1);
private bool _hasCheckedConfigDir;
public ConfigurationService()
private ConfigurationService()
{
var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
_configDir = Path.Combine(appData, "HashTool", "settings");
+1 -1
View File
@@ -4,6 +4,6 @@ public static class HashTypeExtensions
{
public static bool IsInsecure(this HashType type)
{
return type == HashType.MD5 || type == HashType.SHA1;
return type is HashType.MD5 or HashType.SHA1;
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ public partial class LocalizationService : ObservableObject
[ObservableProperty] private LanguageItem _selectedLanguage;
public LocalizationService()
private LocalizationService()
{
_systemUICulture = CultureInfo.CurrentUICulture;
_systemCulture = CultureInfo.CurrentCulture;
+1 -1
View File
@@ -33,7 +33,7 @@ public partial class LoggerService : ObservableObject
[ObservableProperty] private bool _isRecording = true;
[ObservableProperty] private bool _isSavingDebugLog;
public LoggerService()
private LoggerService()
{
var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
_logBaseDir = Path.Combine(appData, "HashTool", "log");
+1 -1
View File
@@ -29,7 +29,7 @@ public class UpdateService
private UpdateManager? _manager;
public UpdateService()
private UpdateService()
{
_httpClient = new HttpClient();
_httpClient.Timeout = TimeSpan.FromSeconds(30);
+4 -4
View File
@@ -45,7 +45,7 @@ public partial class MainWindowViewModel : ObservableObject
public SettingsViewModel SettingsVM => _settingsVM ??= new SettingsViewModel();
public FontService FontConfig => FontService.Instance;
public ThemeService Theme => ThemeService.Instance;
private ThemeService Theme => ThemeService.Instance;
public string MenuCreateText => L["Menu_Create"];
public string MenuCheckText => L["Menu_Check"];
@@ -99,13 +99,13 @@ public partial class MainWindowViewModel : ObservableObject
}
private UpdateViewModel? _updateVM;
public UpdateViewModel UpdateVM => _updateVM ??= new UpdateViewModel();
private UpdateViewModel UpdateVM => _updateVM ??= new UpdateViewModel();
private AboutViewModel? _aboutVM;
public AboutViewModel AboutVM => _aboutVM ??= new AboutViewModel();
private AboutViewModel AboutVM => _aboutVM ??= new AboutViewModel();
private DeveloperViewModel? _developerVM;
public DeveloperViewModel DeveloperVM => _developerVM ??= new DeveloperViewModel();
private DeveloperViewModel DeveloperVM => _developerVM ??= new DeveloperViewModel();
public bool IsBusy => (_createHashVM?.IsComputing ?? false) || (_checkHashVM?.IsChecking ?? false);
public bool IsIdle => !IsBusy;
+36 -3
View File
@@ -128,6 +128,34 @@ public partial class SettingsViewModel : ObservableObject
Font.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(Font.IsLockedFont)) OnPropertyChanged(nameof(CanChangeFont));
if (!_isInitializing)
{
_ = SaveSettingsAsync();
string logMessage;
// Use string literals to avoid potential nameof issues with generated properties
switch (e.PropertyName)
{
case "SelectedFont":
logMessage = $"Font Family changed to: {Font.SelectedFont?.Name ?? "Default"}";
break;
case "BaseFontSize":
logMessage = $"Base Font Size changed to: {Font.BaseFontSize}";
break;
case "UiScale":
logMessage = $"UI Scale changed to: {Font.UiScale}";
break;
case "IsAutoFont":
logMessage = $"Auto Font changed to: {Font.IsAutoFont}";
break;
case "IsLockedFont":
logMessage = $"Locked Font changed to: {Font.IsLockedFont}";
break;
default:
logMessage = $"Font setting changed: {e.PropertyName}";
break;
}
Logger.Log(logMessage);
}
};
LocalizationService.Instance.PropertyChanged += (s, e) =>
@@ -389,7 +417,13 @@ public partial class SettingsViewModel : ObservableObject
if (!_isInitializing) _ = SaveSettingsAsync();
}
public async Task LoadSettingsAsync()
partial void OnIsDeveloperModeEnabledChanged(bool value)
{
Logger.IsSavingDebugLog = value;
if (!_isInitializing) _ = SaveSettingsAsync();
}
private async Task LoadSettingsAsync()
{
_isInitializing = true;
try
@@ -413,8 +447,7 @@ public partial class SettingsViewModel : ObservableObject
if (!string.IsNullOrEmpty(config.FontFamily))
{
var font = Font.InstalledFonts.FirstOrDefault(x => x.Name == config.FontFamily);
if (font != null) Font.SelectedFont = font;
Font.SetTargetFont(config.FontFamily);
}
Font.BaseFontSize = config.BaseFontSize;