Skip to content

Commit

Permalink
hotfix for new Legion Space update v1.0.2.5: Controller READY-byte an…
Browse files Browse the repository at this point in the history
…d new DAService Hint
  • Loading branch information
cerahmed committed Dec 18, 2023
1 parent 25cc827 commit 1e3007b
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 4 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.6'
#define MyAppVersion '0.19.1.7'
#define MyAppPublisher 'BenjaminLSR'
#define MyAppCopyright 'Copyright @ BenjaminLSR'
#define MyAppURL 'https://github.com/Valkirie/HandheldCompanion'
Expand Down
5 changes: 3 additions & 2 deletions HandheldCompanion/Controllers/LegionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private enum BackEnum
private const byte BACK_IDX = 19;
private const byte STATUS_IDX = 0;
private const byte PING_IDX = 40;
private HashSet<int> READY_STATES = new HashSet<int>() {25, 60};

private Thread dataThread;
private bool dataThreadRunning;
Expand All @@ -52,7 +53,7 @@ public override bool IsReady
get
{
byte status = GetStatus(STATUS_IDX);
return status == 25;
return READY_STATES.Contains(status);
}
}

Expand Down Expand Up @@ -239,7 +240,7 @@ private async void dataThreadLoop(object? obj)
if (report is not null)
{
// check if packet is safe
if (report.Data[STATUS_IDX] == 25)
if (READY_STATES.Contains(report.Data[STATUS_IDX]))
Data = report.Data;
}
}
Expand Down
107 changes: 107 additions & 0 deletions HandheldCompanion/Controls/Hints/Hint_LegionGoServices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using HandheldCompanion.Devices;
using HandheldCompanion.Utils;
using HandheldCompanion.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;

namespace HandheldCompanion.Controls.Hints
{
public class Hint_LegionGoServices : IHint
{
private List<string> serviceNames = new()
{
"DAService",
};

private List<ServiceController> serviceControllers = new();
private Timer serviceTimer;

public Hint_LegionGoServices() : base()
{
if (MainWindow.CurrentDevice is not LegionGo)
return;

// Get all the services installed on the local computer
ServiceController[] services = ServiceController.GetServices();
foreach (string serviceName in serviceNames)
{
if (services.Any(s => serviceNames.Contains(s.ServiceName)))
{
// Create a service controller object for the specified service
ServiceController serviceController = new ServiceController(serviceName);
serviceControllers.Add(serviceController);
}
}

// Check if any of the services in the list exist
if (!serviceControllers.Any())
return;

serviceTimer = new Timer(4000);
serviceTimer.Elapsed += ServiceTimer_Elapsed;
serviceTimer.Start();

// default state
this.HintActionButton.Visibility = Visibility.Visible;

this.HintTitle.Text = Properties.Resources.Hint_LegionGoServices;
this.HintDescription.Text = Properties.Resources.Hint_LegionGoServicesDesc;
this.HintReadMe.Text = Properties.Resources.Hint_LegionGoServicesReadme;

this.HintActionButton.Content = Properties.Resources.Hint_LegionGoServicesAction;
}

private void ServiceTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
if(!serviceControllers.Any())
return;

// Check if any of the services in the list exist and are running
bool anyRunning = false;

foreach (ServiceController serviceController in serviceControllers)
{
serviceController.Refresh();
if (serviceController.Status == ServiceControllerStatus.Running)
{
anyRunning = true;
break;
}
}

// UI thread (async)
Application.Current.Dispatcher.BeginInvoke(() =>
{
this.Visibility = anyRunning ? Visibility.Visible : Visibility.Collapsed;
});
}

protected override void HintActionButton_Click(object sender, RoutedEventArgs e)
{
if (!serviceControllers.Any())
return;

Task.Run(async () =>
{
foreach (ServiceController serviceController in serviceControllers)
{
if (serviceController.Status == ServiceControllerStatus.Running)
serviceController.Stop();
serviceController.WaitForStatus(ServiceControllerStatus.Stopped);
ServiceUtils.ChangeStartMode(serviceController, ServiceStartMode.Disabled, out _);
}
});
}

public override void Stop()
{
serviceTimer.Stop();
base.Stop();
}
}
}
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.6</Version>
<Version>0.19.1.7</Version>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU;x64;x86</Platforms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
36 changes: 36 additions & 0 deletions HandheldCompanion/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions HandheldCompanion/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2673,4 +2673,16 @@ with motion input toggle, press selected button(s) to switch from enabled to dis
<data name="DevicePage_FullFanSpeedText" xml:space="preserve">
<value>Fan max speed override</value>
</data>
<data name="Hint_LegionGoServices" xml:space="preserve">
<value>Legion Space Daemon is active</value>
</data>
<data name="Hint_LegionGoServicesAction" xml:space="preserve">
<value>Disable Legion Space Daemon</value>
</data>
<data name="Hint_LegionGoServicesDesc" xml:space="preserve">
<value>Legion Space Daemon is already active on your console. This may cause compatibility issues with the application.</value>
</data>
<data name="Hint_LegionGoServicesReadme" xml:space="preserve">
<value>You should disable Legion Space Daemon, so that the application can run properly and without any errors</value>
</data>
</root>
1 change: 1 addition & 0 deletions HandheldCompanion/Views/Pages/NotificationsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<ui:SimpleStackPanel Name="Notifications" Spacing="6">

<hints:Hint_LegionGoDaemon d:Visibility="Visible" />
<hints:Hint_LegionGoServices d:Visibility="Visible" />
<hints:Hint_RogAllyServiceCheck d:Visibility="Visible" />
<hints:Hint_SteamNeptuneDesktop d:Visibility="Visible" />
<hints:Hint_SteamXboxDrivers d:Visibility="Visible" />
Expand Down

0 comments on commit 1e3007b

Please sign in to comment.