Skip to content

Commit

Permalink
build 0.22.0.3 (#373)
Browse files Browse the repository at this point in the history
* Fixed an issue preventing Quicktools window from moving to the right display on settings change

* Fixed an issue causing a crash when main screen is changed on windows settings

* Fixed an issue causing UI manager to crash when failing to retrieve the currently targeted ComboBox

* remove deprecated ui:WindowHelper.UseAcrylicBackdrop and ui:WindowHelper.UseAeroBackdrop

* Set PublishReadyToRun to true

* Prevent HC from recreating default hotkeys if user already have defined ones

* Fixed an issue causing hotkeys to duplicate on reboot when ButtonFlags is already used

* use Task.Delay().ConfigureAwait(false) when outside UI thread

* remove outdated temperature hack for Galileo (Steam Deck)

* Increase HidDevice Read loop priority

* Reduce CPU overhead when using NeptuneController (Steam Deck) and Gordon Controller (Steam Controller)

* rollback ButtonState and AxisState ConcurrentDictionary

* build 0.22.0.3
  • Loading branch information
Valkirie authored Dec 6, 2024
1 parent 528c697 commit 588920e
Show file tree
Hide file tree
Showing 40 changed files with 165 additions and 145 deletions.
2 changes: 1 addition & 1 deletion HandheldCompanion.iss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define InstallerVersion '0.2'
#define MyAppSetupName 'Handheld Companion'
#define MyBuildId 'HandheldCompanion'
#define MyAppVersion '0.22.0.2'
#define MyAppVersion '0.22.0.3'
#define MyAppPublisher 'BenjaminLSR'
#define MyAppCopyright 'Copyright @ BenjaminLSR'
#define MyAppURL 'https://github.com/Valkirie/HandheldCompanion'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void Execute(bool IsKeyDown, bool IsKeyUp, bool IsBackground)
{
// Start a new osk.exe process
Process OSK = Process.Start(new ProcessStartInfo("osk.exe") { UseShellExecute = true, WindowStyle = ProcessWindowStyle.Hidden });
await Task.Delay(200);
await Task.Delay(200).ConfigureAwait(false); // Avoid blocking the synchronization context

// Find the OSK window.
IntPtr hwndOSK = FindWindow("OSKMainClass", null);
Expand Down
10 changes: 5 additions & 5 deletions HandheldCompanion/Controllers/GordonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ public override void UpdateInputs(long ticks, float delta)

base.UpdateInputs(ticks, delta);
}
private async Task OnControllerInputReceived(GordonControllerInputEventArgs input)
{
this.input = input;
}

public override void Plug()
{
try
{
Controller.OnControllerInputReceived = input => OnControllerInputReceived(input);
Controller.OnControllerInputReceived += input =>
{
this.input = input;
return Task.CompletedTask;
};

// open controller
Open();
Expand Down
4 changes: 2 additions & 2 deletions HandheldCompanion/Controllers/IController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public virtual void Rumble(int delay = 125, byte LargeMotor = byte.MaxValue, byt
rumbleTask = Task.Run(async () =>
{
SetVibration(LargeMotor, SmallMotor);
await Task.Delay(delay);
await Task.Delay(delay).ConfigureAwait(false); // Avoid blocking the synchronization context
SetVibration(0, 0);
});
}
Expand Down Expand Up @@ -365,7 +365,7 @@ public virtual void CyclePort()
Task.Run(async () =>
{
Details.Uninstall(false);
await Task.Delay(3000);
await Task.Delay(3000).ConfigureAwait(false); // Avoid blocking the synchronization context
Devcon.Refresh();
});
break;
Expand Down
13 changes: 6 additions & 7 deletions HandheldCompanion/Controllers/NeptuneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ private void Open()
Controller.RequestLizardMode(false);

// create handler
Controller.OnControllerInputReceived += input => OnControllerInputReceived(input);
Controller.OnControllerInputReceived += input =>
{
this.input = input;
return Task.CompletedTask;
};
}
catch { }
}

private async Task OnControllerInputReceived(NeptuneControllerInputEventArgs input)
{
this.input = input;
}

private void Close()
{
try
Expand Down Expand Up @@ -394,7 +393,7 @@ private async void RumbleThreadLoop(object? obj)
if (GetHapticIntensity(FeedbackSmallMotor, MinIntensity, MaxIntensity, out var rightIntensity))
Controller.SetHaptic2(SCHapticMotor.Right, NCHapticStyle.Weak, rightIntensity);

await Task.Delay(TimerManager.GetPeriod() * 2);
Thread.Sleep(TimerManager.GetPeriod() * 2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Controls/Hints/Hint_SteamInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void HintActionButton_Click(object sender, RoutedEventArgs e)
// halt steam and wait
PlatformManager.Steam.StopProcess();
while (PlatformManager.Steam.IsRunning)
await Task.Delay(1000);
await Task.Delay(1000).ConfigureAwait(false); // Avoid blocking the synchronization context;

// overwrite desktop layout
PlatformManager.Steam.SetUseSteamControllerConfigValue(0);
Expand Down
4 changes: 2 additions & 2 deletions HandheldCompanion/Devices/ASUS/ROGAlly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ private void HandleEvent(byte key)
case 56: // Armory crate: Click
case 166: // Command center: Click
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(KeyPressDelay);
await Task.Delay(KeyPressDelay).ConfigureAwait(false); // Avoid blocking the synchronization context
KeyRelease(button);
});
}
Expand Down
4 changes: 2 additions & 2 deletions HandheldCompanion/Devices/MSI/ClawA1M.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ private void onWMIEvent(object sender, EventArrivedEventArgs e)
case WMIEventCode.LaunchMcxMainUI: // MSI Claw: Click
case WMIEventCode.LaunchMcxOSD: // Quick Settings: Click
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(KeyPressDelay);
await Task.Delay(KeyPressDelay).ConfigureAwait(false); // Avoid blocking the synchronization context
KeyRelease(button);
});
}
Expand Down
3 changes: 2 additions & 1 deletion HandheldCompanion/HandheldCompanion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
<StartupObject>HandheldCompanion.App</StartupObject>
<OutputPath>$(SolutionDir)bin\$(Configuration)</OutputPath>
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>
<Version>0.22.0.2</Version>
<Version>0.22.0.3</Version>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU;x64;x86</Platforms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
11 changes: 6 additions & 5 deletions HandheldCompanion/Inputs/AxisState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -8,9 +9,9 @@ namespace HandheldCompanion.Inputs;
[Serializable]
public partial class AxisState : ICloneable
{
public Dictionary<AxisFlags, short> State = new();
public ConcurrentDictionary<AxisFlags, short> State = new();

public AxisState(Dictionary<AxisFlags, short> State)
public AxisState(ConcurrentDictionary<AxisFlags, short> State)
{
foreach (var state in State)
this[state.Key] = state.Value;
Expand All @@ -24,7 +25,7 @@ public AxisState()

public short this[AxisFlags axis]
{
get => !State.ContainsKey(axis) ? (short)0 : State[axis];
get => State.TryGetValue(axis, out short value) ? value : (short)0;

set => State[axis] = value;
}
Expand Down Expand Up @@ -77,8 +78,8 @@ public override bool Equals(object obj)
return false;
}

public static bool EqualsWithValues(Dictionary<AxisFlags, short> obj1,
Dictionary<AxisFlags, short> obj2)
public static bool EqualsWithValues(ConcurrentDictionary<AxisFlags, short> obj1,
ConcurrentDictionary<AxisFlags, short> obj2)
{
if (obj1.Count != obj2.Count) return false;
{
Expand Down
7 changes: 4 additions & 3 deletions HandheldCompanion/Inputs/ButtonState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -8,9 +9,9 @@ namespace HandheldCompanion.Inputs;
[Serializable]
public partial class ButtonState : ICloneable
{
public Dictionary<ButtonFlags, bool> State = new();
public ConcurrentDictionary<ButtonFlags, bool> State = new();

public ButtonState(Dictionary<ButtonFlags, bool> State)
public ButtonState(ConcurrentDictionary<ButtonFlags, bool> State)
{
foreach (var state in State)
this[state.Key] = state.Value;
Expand All @@ -24,7 +25,7 @@ public ButtonState()

public bool this[ButtonFlags button]
{
get => State.ContainsKey(button) && State[button];
get => State.TryGetValue(button, out bool value) && value;

set => State[button] = value;
}
Expand Down
12 changes: 6 additions & 6 deletions HandheldCompanion/Managers/ControllerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private static async void HidDeviceArrived(PnPDetails details, Guid InterfaceGui
}
catch
{
await Task.Delay(1000);
await Task.Delay(1000).ConfigureAwait(false); // Avoid blocking the synchronization context
}
}

Expand Down Expand Up @@ -600,7 +600,7 @@ private static async void HidDeviceArrived(PnPDetails details, Guid InterfaceGui
}

while (!controller.IsReady && controller.IsConnected())
await Task.Delay(250);
await Task.Delay(250).ConfigureAwait(false); // Avoid blocking the synchronization context

// set (un)busy
controller.IsBusy = false;
Expand Down Expand Up @@ -640,7 +640,7 @@ private static async void HidDeviceRemoved(PnPDetails details, Guid IntefaceGuid
if (Controllers.TryGetValue(details.baseContainerDeviceInstanceId, out controller))
break;

await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false); // Avoid blocking the synchronization context
}

if (controller is null)
Expand Down Expand Up @@ -693,7 +693,7 @@ private static void watchdogThreadLoop(object? obj)

foreach (XInputController xInputController in Controllers.Values.Where(c => c.Details is not null && c.Details.isXInput))
{
byte UserIndex = DeviceManager.GetXInputIndexAsync(xInputController.Details.baseContainerDevicePath);
byte UserIndex = DeviceManager.GetXInputIndexAsync(xInputController.Details.baseContainerDevicePath, true);

// controller is not ready yet
if (UserIndex == byte.MaxValue)
Expand Down Expand Up @@ -882,7 +882,7 @@ private static async void XUsbDeviceArrived(PnPDetails details, Guid IntefaceGui
}

while (!controller.IsReady && controller.IsConnected())
await Task.Delay(250);
await Task.Delay(250).ConfigureAwait(false); // Avoid blocking the synchronization context

// set (un)busy
controller.IsBusy = false;
Expand Down Expand Up @@ -932,7 +932,7 @@ private static async void XUsbDeviceRemoved(PnPDetails details, Guid IntefaceGui
if (Controllers.TryGetValue(details.baseContainerDeviceInstanceId, out controller))
break;

await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false); // Avoid blocking the synchronization context
}

if (controller is null)
Expand Down
14 changes: 7 additions & 7 deletions HandheldCompanion/Managers/DeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private static void XUsbDevice_DeviceRemoved(DeviceEventArgs obj)
while (DateTime.Now < timeout && deviceEx is null)
{
deviceEx = FindDevice(InstanceId);
await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false); // Avoid blocking the synchronization context
}

if (deviceEx is null)
Expand Down Expand Up @@ -533,7 +533,7 @@ private static void XUsbDevice_DeviceArrived(DeviceEventArgs obj)
while (DateTime.Now < timeout && deviceEx is null)
{
deviceEx = FindDevice(InstanceId);
await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false); // Avoid blocking the synchronization context
}

if (deviceEx is not null && deviceEx.isGaming)
Expand All @@ -542,7 +542,7 @@ private static void XUsbDevice_DeviceArrived(DeviceEventArgs obj)
deviceEx.baseContainerDevicePath = obj.SymLink;

if (deviceEx.EnumeratorName.Equals("USB"))
deviceEx.XInputUserIndex = GetXInputIndexAsync(obj.SymLink);
deviceEx.XInputUserIndex = GetXInputIndexAsync(obj.SymLink, false);

if (deviceEx.XInputUserIndex == byte.MaxValue)
deviceEx.XInputDeviceIdx = GetDeviceIndex(obj.SymLink);
Expand Down Expand Up @@ -576,7 +576,7 @@ private static void HidDevice_DeviceRemoved(DeviceEventArgs obj)
while (DateTime.Now < timeout && deviceEx is null)
{
deviceEx = FindDevice(InstanceId);
await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false); // Avoid blocking the synchronization context
}

// skip if XInput
Expand Down Expand Up @@ -610,7 +610,7 @@ private static void HidDevice_DeviceArrived(DeviceEventArgs obj)
while (DateTime.Now < timeout && deviceEx is null)
{
deviceEx = GetDetails(obj.SymLink);
await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false); // Avoid blocking the synchronization context
}

// skip if XInput
Expand Down Expand Up @@ -662,7 +662,7 @@ private static void UsbDevice_DeviceArrived(DeviceEventArgs obj)
}
}

public static byte GetXInputIndexAsync(string SymLink)
public static byte GetXInputIndexAsync(string SymLink, bool UIthread)
{
byte ledState = 0;

Expand All @@ -684,7 +684,7 @@ public static byte GetXInputIndexAsync(string SymLink)
ledState = ledStateData[2];
}

Task.Delay(1000);
Task.Delay(1000).ConfigureAwait(UIthread);
}

return XINPUT_LED_TO_PORT_MAP[ledState];
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Managers/DynamicLightingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static async void InitializeDirect3DDevice()
if (ex.ResultCode == ResultCode.DeviceLost)
{
while (device is not null && device.TestCooperativeLevel() == ResultCode.DeviceLost)
await Task.Delay(100);
await Task.Delay(100).ConfigureAwait(false); // Avoid blocking the synchronization context

// Recreate the device and resources
ReleaseDirect3DDevice();
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Managers/GPUManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static void GPUDisconnect(GPU GPU)
private static void MultimediaManager_PrimaryScreenChanged(DesktopScreen screen)
{
AdapterInformation key = DisplayGPU.Keys.FirstOrDefault(GPU => GPU.Details.DeviceName == screen.screen.DeviceName);
if (DisplayGPU.TryGetValue(key, out GPU gpu))
if (key is not null && DisplayGPU.TryGetValue(key, out GPU gpu))
{
LogManager.LogError("Retrieved DisplayAdapter: {0} for screen: {1}", gpu.ToString(), screen.screen.DeviceName);

Expand Down
Loading

0 comments on commit 588920e

Please sign in to comment.