Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| afa7bd987a | |||
| 4cd7e74923 | |||
| d65c556656 |
@@ -11,9 +11,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.5" />
|
||||
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.6" />
|
||||
<PackageReference Include="PipeMethodCalls" Version="4.0.3" />
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog" Version="4.3.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.12.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace HardwareMonitorStatusWindow.StatusWindow;
|
||||
|
||||
public partial class App
|
||||
{
|
||||
private List<IDisposable> _windowSourceList;
|
||||
private List<IDisposable>? _windowSourceList;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
@@ -30,7 +30,7 @@ public partial class App
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
_windowSourceList.ForEach(ws => ws.Dispose());
|
||||
_windowSourceList?.ForEach(ws => ws.Dispose());
|
||||
|
||||
base.OnExit(e);
|
||||
}
|
||||
|
||||
@@ -6,15 +6,16 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
|
||||
namespace HardwareMonitorStatusWindow.StatusWindow;
|
||||
|
||||
internal static class Data
|
||||
{
|
||||
private static PipeClient<IHardwareMonitorService> _pipeClient;
|
||||
private static IEnumerable<Hardware> _hardware;
|
||||
private static PipeClient<IHardwareMonitorService>? _pipeClient;
|
||||
private static IEnumerable<Hardware>? _hardware;
|
||||
|
||||
internal static ObservableCollection<SensorEntry> SensorEntries { get; set; }
|
||||
internal static ObservableCollection<SensorEntry> SensorEntries { get; set; } = [];
|
||||
|
||||
internal static async Task LoadComputer()
|
||||
{
|
||||
@@ -25,7 +26,7 @@ internal static class Data
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
Log.Error(exception, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +37,14 @@ internal static class Data
|
||||
|
||||
internal static void CloseComputer()
|
||||
{
|
||||
_pipeClient.Dispose();
|
||||
_pipeClient?.Dispose();
|
||||
}
|
||||
|
||||
internal static IList<Hardware> ComputerHardware => _hardware.ToList();
|
||||
internal static IList<Hardware> ComputerHardware => _hardware?.ToList() ?? [];
|
||||
|
||||
internal static void Load()
|
||||
{
|
||||
SensorEntries = JsonSerializer.Deserialize<ObservableCollection<SensorEntry>>(Settings.Default.Sensors);
|
||||
SensorEntries = JsonSerializer.Deserialize<ObservableCollection<SensorEntry>>(Settings.Default.Sensors) ?? [];
|
||||
}
|
||||
|
||||
internal static void Save()
|
||||
|
||||
@@ -7,15 +7,18 @@ namespace HardwareMonitorStatusWindow.StatusWindow;
|
||||
|
||||
internal class DataErrorDictionary : Dictionary<string, List<string>>
|
||||
{
|
||||
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
|
||||
public event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
|
||||
|
||||
private void OnErrorsChanged(string propertyName)
|
||||
{
|
||||
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public IEnumerable GetErrors(string propertyName)
|
||||
public IEnumerable? GetErrors(string? propertyName)
|
||||
{
|
||||
if (propertyName == null)
|
||||
return null;
|
||||
|
||||
return TryGetValue(propertyName, out var value) ? value : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Serilog;
|
||||
using HardwareMonitorStatusWindow.Service;
|
||||
using Microsoft.Win32.TaskScheduler;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Velopack;
|
||||
@@ -17,7 +19,30 @@ internal class Program
|
||||
|
||||
Log.Information("Start");
|
||||
|
||||
VelopackApp.Build().SetLogger(new SerilogVelopackLogger()).Run();
|
||||
var stopServiceHook = new VelopackHook(_ =>
|
||||
{
|
||||
try
|
||||
{
|
||||
using var taskService = new TaskService();
|
||||
|
||||
Log.Information("Checking for task name: {name}", HardwareMonitorService.ScheduledTaskName);
|
||||
|
||||
var existingTask = taskService.FindTask(HardwareMonitorService.ScheduledTaskName);
|
||||
|
||||
Log.Information("Task: {existingTask}", existingTask);
|
||||
|
||||
Log.Information("Stopping task");
|
||||
|
||||
existingTask?.Stop();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Ignored
|
||||
Log.Error(exception, "");
|
||||
}
|
||||
});
|
||||
|
||||
VelopackApp.Build().OnBeforeUpdateFastCallback(stopServiceHook).OnBeforeUninstallFastCallback(stopServiceHook).SetLogger(new SerilogVelopackLogger()).Run();
|
||||
|
||||
var app = new App();
|
||||
app.InitializeComponent();
|
||||
|
||||
@@ -11,15 +11,14 @@ namespace HardwareMonitorStatusWindow.StatusWindow;
|
||||
|
||||
public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
||||
{
|
||||
private readonly DataErrorDictionary _dataErrorDictionary;
|
||||
private readonly DataErrorDictionary _dataErrorDictionary = new();
|
||||
|
||||
public SensorEntry()
|
||||
{
|
||||
_dataErrorDictionary = new DataErrorDictionary();
|
||||
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
|
||||
}
|
||||
|
||||
public string Label
|
||||
public string? Label
|
||||
{
|
||||
get;
|
||||
set
|
||||
@@ -31,7 +30,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
||||
}
|
||||
}
|
||||
|
||||
public string HardwareId
|
||||
public string? HardwareId
|
||||
{
|
||||
get;
|
||||
set
|
||||
@@ -41,7 +40,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
||||
}
|
||||
}
|
||||
|
||||
public string SensorId
|
||||
public string? SensorId
|
||||
{
|
||||
get;
|
||||
set
|
||||
@@ -52,7 +51,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public Hardware? Hardware => Data.ComputerHardware.FirstOrDefault(h => h.Identifier.ToString() == HardwareId);
|
||||
public Hardware? Hardware => Data.ComputerHardware?.FirstOrDefault(h => h.Identifier.ToString() == HardwareId);
|
||||
|
||||
[JsonIgnore]
|
||||
public Sensor? Sensor => Hardware?.Sensors.FirstOrDefault(s => s.Identifier.ToString() == SensorId);
|
||||
@@ -60,19 +59,22 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
||||
[JsonIgnore]
|
||||
public bool HasErrors => _dataErrorDictionary.Any();
|
||||
|
||||
public IEnumerable GetErrors(string propertyName)
|
||||
public IEnumerable GetErrors(string? propertyName)
|
||||
{
|
||||
return _dataErrorDictionary.GetErrors(propertyName);
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
return _dataErrorDictionary.GetErrors(propertyName) ?? Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
|
||||
public event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
|
||||
|
||||
private void DataErrorDictionaryErrorsChanged(object sender, DataErrorsChangedEventArgs e)
|
||||
private void DataErrorDictionaryErrorsChanged(object? sender, DataErrorsChangedEventArgs e)
|
||||
{
|
||||
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(e.PropertyName));
|
||||
}
|
||||
|
||||
private bool ValidateLabel(string newValue)
|
||||
private bool ValidateLabel(string? newValue)
|
||||
{
|
||||
_dataErrorDictionary.ClearErrors(nameof(Label));
|
||||
|
||||
@@ -84,14 +86,14 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
||||
return false;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
|
||||
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
||||
field = value;
|
||||
|
||||
@@ -58,12 +58,12 @@
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Path=Hardware.Type}"
|
||||
<TextBlock Text="{Binding Path=Hardware.Type, FallbackValue=null}"
|
||||
Height="Auto"
|
||||
FontSize="10"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,2,0,2" />
|
||||
<TextBlock Text="{Binding Path=Hardware.Name}"
|
||||
<TextBlock Text="{Binding Path=Hardware.Name, FallbackValue=null}"
|
||||
Height="Auto"
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
@@ -75,12 +75,12 @@
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Path=Sensor.Type}"
|
||||
<TextBlock Text="{Binding Path=Sensor.Type, FallbackValue=null}"
|
||||
Height="Auto"
|
||||
FontSize="10"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,2,0,2" />
|
||||
<TextBlock Text="{Binding Path=Sensor.Name}"
|
||||
<TextBlock Text="{Binding Path=Sensor.Name, FallbackValue=null}"
|
||||
Height="Auto"
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
|
||||
|
||||
public partial class HardwareSettingsPanel
|
||||
{
|
||||
private CollectionViewSource _collectionViewSource;
|
||||
private CollectionViewSource? _collectionViewSource;
|
||||
|
||||
public HardwareSettingsPanel()
|
||||
{
|
||||
@@ -105,7 +105,7 @@ public partial class HardwareSettingsPanel
|
||||
SensorDataGrid.SelectedItems.CopyTo(selectedItems, 0);
|
||||
|
||||
foreach (var sensorEntry in selectedItems)
|
||||
Data.SensorEntries.Remove(sensorEntry);
|
||||
Data.SensorEntries?.Remove(sensorEntry);
|
||||
|
||||
SetSensorButtonStates();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public partial class SensorWindow
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public bool? Display(SensorEntry sensorEntry, Window owner)
|
||||
public bool? Display(SensorEntry sensorEntry, Window? owner)
|
||||
{
|
||||
DataContext = sensorEntry;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using HardwareMonitorStatusWindow.StatusWindow;
|
||||
|
||||
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
<PackageReference Include="ChrisKaczor.Wpf.Controls.Link" Version="1.0.4" />
|
||||
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.4" />
|
||||
<PackageReference Include="ChrisKaczor.Wpf.Windows.CategoryWindow" Version="1.0.2" />
|
||||
<PackageReference Include="ChrisKaczor.Wpf.Windows.FloatingStatusWindow" Version="2.0.0.7" />
|
||||
<PackageReference Include="ChrisKaczor.Wpf.Windows.FloatingStatusWindow" Version="2.0.0.8" />
|
||||
<PackageReference Include="gong-wpf-dragdrop" Version="4.0.0" />
|
||||
<PackageReference Include="PipeMethodCalls" Version="4.0.3" />
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog" Version="4.3.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageReference Include="Velopack" Version="0.0.1298" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using ChrisKaczor.Wpf.Windows.FloatingStatusWindow;
|
||||
using HardwareMonitorStatusWindow.Service;
|
||||
using HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
|
||||
using LibreHardwareMonitor.PawnIo;
|
||||
using Microsoft.Win32.TaskScheduler;
|
||||
using Serilog;
|
||||
using System;
|
||||
@@ -23,13 +24,24 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
private readonly FloatingStatusWindow _floatingStatusWindow;
|
||||
private readonly Timer _timer;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
|
||||
|
||||
internal WindowSource()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var taskService = new TaskService();
|
||||
|
||||
if (!PawnIo.IsInstalled)
|
||||
{
|
||||
Log.Information("PawnIO not installed");
|
||||
}
|
||||
else
|
||||
{
|
||||
var pawnIoVersion = PawnIo.Version;
|
||||
|
||||
Log.Information("PawnIO installed: {version}", pawnIoVersion);
|
||||
}
|
||||
|
||||
Log.Information("Checking for task name: {name}", HardwareMonitorService.ScheduledTaskName);
|
||||
|
||||
var existingTask = taskService.FindTask(HardwareMonitorService.ScheduledTaskName);
|
||||
@@ -152,7 +164,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
Data.Load();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
private static void Save()
|
||||
{
|
||||
Data.Save();
|
||||
}
|
||||
@@ -231,6 +243,9 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
|
||||
foreach (var sensorEntry in Data.SensorEntries)
|
||||
{
|
||||
if (sensorEntry.Sensor == null)
|
||||
continue;
|
||||
|
||||
if (text.Length > 0)
|
||||
text.AppendLine();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user