mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
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:
@@ -146,14 +146,7 @@ namespace PowerDisplay
|
||||
|
||||
private void ShowError(string message)
|
||||
{
|
||||
if (_viewModel != null)
|
||||
{
|
||||
_viewModel.StatusText = $"Error: {message}";
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError($"Error (ViewModel not yet initialized): {message}");
|
||||
}
|
||||
Logger.LogError($"Error: {message}");
|
||||
}
|
||||
|
||||
private void OnWindowActivated(object sender, WindowActivatedEventArgs args)
|
||||
@@ -398,10 +391,6 @@ namespace PowerDisplay
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"OnRefreshClick failed: {ex}");
|
||||
if (_viewModel != null)
|
||||
{
|
||||
_viewModel.StatusText = "Refresh failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ public partial class MainViewModel
|
||||
{
|
||||
try
|
||||
{
|
||||
StatusText = "Scanning monitors...";
|
||||
IsScanning = true;
|
||||
|
||||
// Discover monitors
|
||||
@@ -41,21 +40,11 @@ public partial class MainViewModel
|
||||
|
||||
// Start watching for display changes after initialization
|
||||
StartDisplayWatching();
|
||||
|
||||
if (monitors.Count > 0)
|
||||
{
|
||||
StatusText = $"Found {monitors.Count} monitors";
|
||||
}
|
||||
else
|
||||
{
|
||||
StatusText = "No controllable monitors found";
|
||||
}
|
||||
}
|
||||
catch (Exception lambdaEx)
|
||||
{
|
||||
Logger.LogError($"[InitializeAsync] UI update failed: {lambdaEx.Message}");
|
||||
IsScanning = false;
|
||||
StatusText = $"UI update failed: {lambdaEx.Message}";
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -64,7 +53,6 @@ public partial class MainViewModel
|
||||
Logger.LogError($"[InitializeAsync] Monitor discovery failed: {ex.Message}");
|
||||
_dispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
StatusText = $"Scan failed: {ex.Message}";
|
||||
IsScanning = false;
|
||||
});
|
||||
}
|
||||
@@ -79,7 +67,6 @@ public partial class MainViewModel
|
||||
|
||||
try
|
||||
{
|
||||
StatusText = "Refreshing monitor list...";
|
||||
IsScanning = true;
|
||||
|
||||
var monitors = await _monitorManager.DiscoverMonitorsAsync(_cancellationTokenSource.Token);
|
||||
@@ -88,14 +75,13 @@ public partial class MainViewModel
|
||||
{
|
||||
UpdateMonitorList(monitors);
|
||||
IsScanning = false;
|
||||
StatusText = $"Found {monitors.Count} monitors";
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"[RefreshMonitorsAsync] Refresh failed: {ex.Message}");
|
||||
_dispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
StatusText = $"Refresh failed: {ex.Message}";
|
||||
IsScanning = false;
|
||||
});
|
||||
}
|
||||
@@ -190,13 +176,11 @@ public partial class MainViewModel
|
||||
{
|
||||
try
|
||||
{
|
||||
StatusText = $"Setting all monitors brightness to {brightness}%...";
|
||||
await _monitorManager.SetAllBrightnessAsync(brightness, _cancellationTokenSource.Token);
|
||||
StatusText = $"All monitors brightness set to {brightness}%";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusText = $"Failed to set brightness: {ex.Message}";
|
||||
Logger.LogError($"[SetAllBrightnessAsync] Failed to set brightness: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -340,7 +340,6 @@ public partial class MainViewModel
|
||||
{
|
||||
// Set loading state to block UI interactions
|
||||
IsLoading = true;
|
||||
StatusText = "Loading settings...";
|
||||
|
||||
// Read current settings
|
||||
var settings = _settingsUtils.GetSettingsOrDefault<PowerDisplaySettings>("PowerDisplay");
|
||||
@@ -395,8 +394,6 @@ public partial class MainViewModel
|
||||
// Apply feature visibility settings using HardwareId
|
||||
ApplyFeatureVisibility(monitorVm, settings);
|
||||
}
|
||||
|
||||
StatusText = "Saved settings restored successfully";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -427,14 +424,12 @@ public partial class MainViewModel
|
||||
}
|
||||
|
||||
// No need to flush - MonitorStateManager now saves directly!
|
||||
StatusText = "Current monitor values saved to state file";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"[ReloadMonitorSettingsAsync] Failed to reload settings: {ex.Message}");
|
||||
Logger.LogError($"[ReloadMonitorSettingsAsync] Stack trace: {ex.StackTrace}");
|
||||
StatusText = $"Failed to process settings: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -42,7 +42,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
|
||||
|
||||
private ObservableCollection<MonitorViewModel> _monitors;
|
||||
private ObservableCollection<PowerDisplayProfile> _profiles;
|
||||
private string _statusText;
|
||||
private bool _isScanning;
|
||||
private bool _isInitialized;
|
||||
private bool _isLoading;
|
||||
@@ -58,7 +57,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
_monitors = new ObservableCollection<MonitorViewModel>();
|
||||
_profiles = new ObservableCollection<PowerDisplayProfile>();
|
||||
_statusText = "Initializing...";
|
||||
_isScanning = true;
|
||||
|
||||
// Initialize settings utils
|
||||
@@ -107,16 +105,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
|
||||
|
||||
public bool HasProfiles => Profiles.Count > 0;
|
||||
|
||||
public string StatusText
|
||||
{
|
||||
get => _statusText;
|
||||
set
|
||||
{
|
||||
_statusText = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsScanning
|
||||
{
|
||||
get => _isScanning;
|
||||
|
||||
Reference in New Issue
Block a user