Skip to content

Commit

Permalink
build 0.19.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Dec 11, 2023
1 parent 017a16f commit 2678b8b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 52 deletions.
2 changes: 1 addition & 1 deletion HandheldCompanion.iss
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ end;

#define MyAppSetupName 'Handheld Companion'
#define MyBuildId 'HandheldCompanion'
#define MyAppVersion '0.19.1.3'
#define MyAppVersion '0.19.1.4'
#define MyAppPublisher 'BenjaminLSR'
#define MyAppCopyright 'Copyright @ BenjaminLSR'
#define MyAppURL 'https://github.com/Valkirie/HandheldCompanion'
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/HandheldCompanion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<StartupObject>HandheldCompanion.App</StartupObject>
<OutputPath>$(SolutionDir)bin\$(Configuration)</OutputPath>
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>
<Version>0.19.1.3</Version>
<Version>0.19.1.4</Version>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU;x64;x86</Platforms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
108 changes: 58 additions & 50 deletions HandheldCompanion/Managers/ControllerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,77 +852,85 @@ private static async void XUsbDeviceRemoved(PnPDetails details, DeviceEventArgs
ControllerUnplugged?.Invoke(controller, IsPowerCycling);
}

private static object targetLock = new object();

private static void ClearTargetController()
{
// unplug previous controller
if (targetController is not null)
lock (targetLock)
{
targetController.InputsUpdated -= UpdateInputs;
targetController.SetLightColor(0, 0, 0);
targetController.Cleanup();
targetController.Unplug();
targetController = null;

// update HIDInstancePath
SettingsManager.SetProperty("HIDInstancePath", string.Empty);
// unplug previous controller
if (targetController is not null)
{
targetController.InputsUpdated -= UpdateInputs;
targetController.SetLightColor(0, 0, 0);
targetController.Cleanup();
targetController.Unplug();
targetController = null;

// update HIDInstancePath
SettingsManager.SetProperty("HIDInstancePath", string.Empty);
}
}
}

public static void SetTargetController(string baseContainerDeviceInstanceId, bool IsPowerCycling)
{
// look for new controller
if (!Controllers.TryGetValue(baseContainerDeviceInstanceId, out IController controller))
return;
lock (targetLock)
{
// look for new controller
if (!Controllers.TryGetValue(baseContainerDeviceInstanceId, out IController controller))
return;

if (controller.IsVirtual())
return;
if (controller.IsVirtual())
return;

// clear current target
ClearTargetController();
// clear current target
ClearTargetController();

// update target controller
targetController = controller;
targetController.InputsUpdated += UpdateInputs;
targetController.Plug();

Color _systemBackground = MainWindow.uiSettings.GetColorValue(UIColorType.Background);
Color _systemAccent = MainWindow.uiSettings.GetColorValue(UIColorType.Accent);
targetController.SetLightColor(_systemAccent.R, _systemAccent.G, _systemAccent.B);
// update target controller
targetController = controller;
targetController.InputsUpdated += UpdateInputs;
targetController.Plug();

// update HIDInstancePath
SettingsManager.SetProperty("HIDInstancePath", baseContainerDeviceInstanceId);
Color _systemBackground = MainWindow.uiSettings.GetColorValue(UIColorType.Background);
Color _systemAccent = MainWindow.uiSettings.GetColorValue(UIColorType.Accent);
targetController.SetLightColor(_systemAccent.R, _systemAccent.G, _systemAccent.B);

if (!IsPowerCycling)
{
if (SettingsManager.GetBoolean("HIDcloakonconnect"))
{
bool powerCycle = true;
// update HIDInstancePath
SettingsManager.SetProperty("HIDInstancePath", baseContainerDeviceInstanceId);

if (targetController is LegionController)
if (!IsPowerCycling)
{
if (SettingsManager.GetBoolean("HIDcloakonconnect"))
{
// todo: Look for a byte within hid report that'd tend to mean both controllers are synced.
// Then I guess we could try and power cycle them.
powerCycle = !((LegionController)targetController).IsWireless;
}
bool powerCycle = true;

if (!targetController.IsHidden())
targetController.Hide(powerCycle);
if (targetController is LegionController)
{
// todo: Look for a byte within hid report that'd tend to mean both controllers are synced.
// Then I guess we could try and power cycle them.
powerCycle = !((LegionController)targetController).IsWireless;
}

if (!targetController.IsHidden())
targetController.Hide(powerCycle);
}
}
}

// check applicable scenarios
CheckControllerScenario();
// check applicable scenarios
CheckControllerScenario();

// check if controller is about to power cycle
PowerCyclers.TryGetValue(baseContainerDeviceInstanceId, out IsPowerCycling);
// check if controller is about to power cycle
PowerCyclers.TryGetValue(baseContainerDeviceInstanceId, out IsPowerCycling);

if (!IsPowerCycling)
{
if (SettingsManager.GetBoolean("HIDvibrateonconnect"))
targetController.Rumble();
if (!IsPowerCycling)
{
if (SettingsManager.GetBoolean("HIDvibrateonconnect"))
targetController.Rumble();
}

ControllerSelected?.Invoke(targetController);
}

ControllerSelected?.Invoke(targetController);
}

public static bool SuspendController(string baseContainerDeviceInstanceId)
Expand Down

0 comments on commit 2678b8b

Please sign in to comment.