Skip to content

Commit

Permalink
More code clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Jul 11, 2024
1 parent 4d155e1 commit 9f46ee8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
19 changes: 7 additions & 12 deletions ControlApp/Models/DshmDevMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ namespace Nefarius.DsHidMini.ControlApp.Models
{
public class DshmDevMan
{
private DeviceNotificationListener _listener;
private DeviceNotificationListener? _listener;
//private readonly HostRadio _hostRadio;

public List<PnPDevice> Devices { get; private set; } = new();

public DshmDevMan()
{
}

public bool StartListeningForDshmDevices()
{
Log.Logger.Information("Starting detection of DsHidMini devices");
Expand All @@ -33,18 +29,18 @@ public void StopListeningForDshmDevices()
{
Log.Logger.Information("Stopping detection of DsHidMini devices");
Devices.Clear();
_listener.StopListen();
_listener.Dispose();
_listener?.StopListen();
_listener?.Dispose();
_listener = null;
}

public void OnListenerDevicesRemovedOrAdded(DeviceEventArgs e)
private void OnListenerDevicesRemovedOrAdded(DeviceEventArgs e)
{
Log.Logger.Information("DsHidMini devices added or removed. Updating device list");
UpdateConnectedDshmDevicesList();
}

public void UpdateConnectedDshmDevicesList()
private void UpdateConnectedDshmDevicesList()
{
Log.Logger.Debug("Rebuilding list of connected DsHidMini devices");
Devices.Clear();
Expand All @@ -58,8 +54,7 @@ public void UpdateConnectedDshmDevicesList()
ConnectedDeviceListUpdated?.Invoke(this, new());
}


public bool TryReconnectDevice(PnPDevice device)
public static bool TryReconnectDevice(PnPDevice device)
{
Log.Logger.Information($"Attempting on reconnecting device of instance {device.InstanceId}");
string? enumerator = device.GetProperty<string>(DevicePropertyKey.Device_EnumeratorName);
Expand Down Expand Up @@ -97,7 +92,7 @@ public bool TryReconnectDevice(PnPDevice device)
}
}

public event EventHandler ConnectedDeviceListUpdated;
public event EventHandler? ConnectedDeviceListUpdated;

}
}
2 changes: 1 addition & 1 deletion ControlApp/ViewModels/Pages/DevicesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void ReconnectAllDevices()
{
if (devVM.IsHidModeMismatched)
{
if (!_dshmDevMan.TryReconnectDevice(devVM.Device)){
if (!DshmDevMan.TryReconnectDevice(devVM.Device)){
oneOrMoreFails = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ControlApp/ViewModels/UserControls/DeviceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private void ApplyChanges()
[RelayCommand]
private void RestartDevice()
{
bool reconnectionResult = _dshmDevMan.TryReconnectDevice(Device);
bool reconnectionResult = DshmDevMan.TryReconnectDevice(Device);
Log.Logger.Information(
$"User instructed {(IsWireless ? "wireless" : "wired")} device '{DeviceAddress}' to restart/disconnect.");
_appSnackbarMessagesService.ShowPowerCyclingDeviceMessage(IsWireless, SecurityUtil.IsElevated,
Expand Down

0 comments on commit 9f46ee8

Please sign in to comment.