Remove StatusText from ViewModel; use logging for errors

StatusText property and all related UI updates have been removed
from MainViewModel and MainWindow. Status and error messages are
now logged via Logger instead of being shown in the UI. This
simplifies the ViewModel and centralizes error reporting. Only
IsScanning and IsLoading remain for UI state indication.
This commit is contained in:
Yu Leng
2025-12-10 05:01:09 +08:00
parent a0f45c444f
commit b004fe1445
4 changed files with 3 additions and 47 deletions

View File

@@ -146,14 +146,7 @@ namespace PowerDisplay
private void ShowError(string message) private void ShowError(string message)
{ {
if (_viewModel != null) Logger.LogError($"Error: {message}");
{
_viewModel.StatusText = $"Error: {message}";
}
else
{
Logger.LogError($"Error (ViewModel not yet initialized): {message}");
}
} }
private void OnWindowActivated(object sender, WindowActivatedEventArgs args) private void OnWindowActivated(object sender, WindowActivatedEventArgs args)
@@ -398,10 +391,6 @@ namespace PowerDisplay
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError($"OnRefreshClick failed: {ex}"); Logger.LogError($"OnRefreshClick failed: {ex}");
if (_viewModel != null)
{
_viewModel.StatusText = "Refresh failed";
}
} }
} }

View File

@@ -24,7 +24,6 @@ public partial class MainViewModel
{ {
try try
{ {
StatusText = "Scanning monitors...";
IsScanning = true; IsScanning = true;
// Discover monitors // Discover monitors
@@ -41,21 +40,11 @@ public partial class MainViewModel
// Start watching for display changes after initialization // Start watching for display changes after initialization
StartDisplayWatching(); StartDisplayWatching();
if (monitors.Count > 0)
{
StatusText = $"Found {monitors.Count} monitors";
}
else
{
StatusText = "No controllable monitors found";
}
} }
catch (Exception lambdaEx) catch (Exception lambdaEx)
{ {
Logger.LogError($"[InitializeAsync] UI update failed: {lambdaEx.Message}"); Logger.LogError($"[InitializeAsync] UI update failed: {lambdaEx.Message}");
IsScanning = false; IsScanning = false;
StatusText = $"UI update failed: {lambdaEx.Message}";
} }
}); });
} }
@@ -64,7 +53,6 @@ public partial class MainViewModel
Logger.LogError($"[InitializeAsync] Monitor discovery failed: {ex.Message}"); Logger.LogError($"[InitializeAsync] Monitor discovery failed: {ex.Message}");
_dispatcherQueue.TryEnqueue(() => _dispatcherQueue.TryEnqueue(() =>
{ {
StatusText = $"Scan failed: {ex.Message}";
IsScanning = false; IsScanning = false;
}); });
} }
@@ -79,7 +67,6 @@ public partial class MainViewModel
try try
{ {
StatusText = "Refreshing monitor list...";
IsScanning = true; IsScanning = true;
var monitors = await _monitorManager.DiscoverMonitorsAsync(_cancellationTokenSource.Token); var monitors = await _monitorManager.DiscoverMonitorsAsync(_cancellationTokenSource.Token);
@@ -88,14 +75,13 @@ public partial class MainViewModel
{ {
UpdateMonitorList(monitors); UpdateMonitorList(monitors);
IsScanning = false; IsScanning = false;
StatusText = $"Found {monitors.Count} monitors";
}); });
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError($"[RefreshMonitorsAsync] Refresh failed: {ex.Message}");
_dispatcherQueue.TryEnqueue(() => _dispatcherQueue.TryEnqueue(() =>
{ {
StatusText = $"Refresh failed: {ex.Message}";
IsScanning = false; IsScanning = false;
}); });
} }
@@ -190,13 +176,11 @@ public partial class MainViewModel
{ {
try try
{ {
StatusText = $"Setting all monitors brightness to {brightness}%...";
await _monitorManager.SetAllBrightnessAsync(brightness, _cancellationTokenSource.Token); await _monitorManager.SetAllBrightnessAsync(brightness, _cancellationTokenSource.Token);
StatusText = $"All monitors brightness set to {brightness}%";
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusText = $"Failed to set brightness: {ex.Message}"; Logger.LogError($"[SetAllBrightnessAsync] Failed to set brightness: {ex.Message}");
} }
} }

View File

@@ -340,7 +340,6 @@ public partial class MainViewModel
{ {
// Set loading state to block UI interactions // Set loading state to block UI interactions
IsLoading = true; IsLoading = true;
StatusText = "Loading settings...";
// Read current settings // Read current settings
var settings = _settingsUtils.GetSettingsOrDefault<PowerDisplaySettings>("PowerDisplay"); var settings = _settingsUtils.GetSettingsOrDefault<PowerDisplaySettings>("PowerDisplay");
@@ -395,8 +394,6 @@ public partial class MainViewModel
// Apply feature visibility settings using HardwareId // Apply feature visibility settings using HardwareId
ApplyFeatureVisibility(monitorVm, settings); ApplyFeatureVisibility(monitorVm, settings);
} }
StatusText = "Saved settings restored successfully";
} }
else else
{ {
@@ -427,14 +424,12 @@ public partial class MainViewModel
} }
// No need to flush - MonitorStateManager now saves directly! // No need to flush - MonitorStateManager now saves directly!
StatusText = "Current monitor values saved to state file";
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError($"[ReloadMonitorSettingsAsync] Failed to reload settings: {ex.Message}"); Logger.LogError($"[ReloadMonitorSettingsAsync] Failed to reload settings: {ex.Message}");
Logger.LogError($"[ReloadMonitorSettingsAsync] Stack trace: {ex.StackTrace}"); Logger.LogError($"[ReloadMonitorSettingsAsync] Stack trace: {ex.StackTrace}");
StatusText = $"Failed to process settings: {ex.Message}";
} }
finally finally
{ {

View File

@@ -42,7 +42,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
private ObservableCollection<MonitorViewModel> _monitors; private ObservableCollection<MonitorViewModel> _monitors;
private ObservableCollection<PowerDisplayProfile> _profiles; private ObservableCollection<PowerDisplayProfile> _profiles;
private string _statusText;
private bool _isScanning; private bool _isScanning;
private bool _isInitialized; private bool _isInitialized;
private bool _isLoading; private bool _isLoading;
@@ -58,7 +57,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
_cancellationTokenSource = new CancellationTokenSource(); _cancellationTokenSource = new CancellationTokenSource();
_monitors = new ObservableCollection<MonitorViewModel>(); _monitors = new ObservableCollection<MonitorViewModel>();
_profiles = new ObservableCollection<PowerDisplayProfile>(); _profiles = new ObservableCollection<PowerDisplayProfile>();
_statusText = "Initializing...";
_isScanning = true; _isScanning = true;
// Initialize settings utils // Initialize settings utils
@@ -107,16 +105,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
public bool HasProfiles => Profiles.Count > 0; public bool HasProfiles => Profiles.Count > 0;
public string StatusText
{
get => _statusText;
set
{
_statusText = value;
OnPropertyChanged();
}
}
public bool IsScanning public bool IsScanning
{ {
get => _isScanning; get => _isScanning;