diff --git a/HandheldCompanion.iss b/HandheldCompanion.iss index 3cf17cc2c..e29b45790 100644 --- a/HandheldCompanion.iss +++ b/HandheldCompanion.iss @@ -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' diff --git a/HandheldCompanion/Controllers/LegionController.cs b/HandheldCompanion/Controllers/LegionController.cs index c904d51f7..d3ea3b717 100644 --- a/HandheldCompanion/Controllers/LegionController.cs +++ b/HandheldCompanion/Controllers/LegionController.cs @@ -42,6 +42,10 @@ private enum BackEnum private const byte BACK_IDX = 19; private const byte STATUS_IDX = 0; private const byte PING_IDX = 40; + private HashSet READY_STATES = new HashSet() {25, 60}; + + private const byte MIN_WIRELESS_STATUS = 40; + private const byte MAX_WIRELESS_STATUS = 50; private Thread dataThread; private bool dataThreadRunning; @@ -52,7 +56,7 @@ public override bool IsReady get { byte status = GetStatus(STATUS_IDX); - return status == 25; + return READY_STATES.Contains(status); } } @@ -60,8 +64,8 @@ public bool IsWireless { get { - byte status = GetStatus(PING_IDX); - return (status >= 40 && status <= 50); + byte status = GetStatus(PING_IDX); + return (status >= MIN_WIRELESS_STATUS && status <= MAX_WIRELESS_STATUS); } } @@ -235,11 +239,12 @@ private async void dataThreadLoop(object? obj) if (hidDevice is null) continue; - HidReport report = hidDevice.ReadReport(); + HidReport report = hidDevice.ReadReport(); + 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; } } @@ -370,17 +375,9 @@ public void HandleTouchpadInput(bool touched, ushort x, ushort y) internal void SetPassthrough(bool enabled) { - switch(enabled) - { - case true: - SetTouchPadStatus(1); - break; - case false: - SetTouchPadStatus(0); - break; - } - + SetTouchPadStatus(enabled ? 1 : 0); IsPassthrough = enabled; } + } } diff --git a/HandheldCompanion/Controls/Hints/Hint_LegionGoServices.cs b/HandheldCompanion/Controls/Hints/Hint_LegionGoServices.cs new file mode 100644 index 000000000..4e23b83c6 --- /dev/null +++ b/HandheldCompanion/Controls/Hints/Hint_LegionGoServices.cs @@ -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 serviceNames = new() + { + "DAService", + }; + + private List 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(); + } + } +} diff --git a/HandheldCompanion/HandheldCompanion.csproj b/HandheldCompanion/HandheldCompanion.csproj index 1fdc42f60..8e60c5062 100644 --- a/HandheldCompanion/HandheldCompanion.csproj +++ b/HandheldCompanion/HandheldCompanion.csproj @@ -12,7 +12,7 @@ HandheldCompanion.App $(SolutionDir)bin\$(Configuration) Resources\icon.ico - 0.19.1.6 + 0.19.1.7 app.manifest AnyCPU;x64;x86 true diff --git a/HandheldCompanion/Properties/Resources.Designer.cs b/HandheldCompanion/Properties/Resources.Designer.cs index 06f264c94..51e39ce08 100644 --- a/HandheldCompanion/Properties/Resources.Designer.cs +++ b/HandheldCompanion/Properties/Resources.Designer.cs @@ -3365,6 +3365,42 @@ public static string Hint_LegionGoDaemonReadme { } } + /// + /// Looks up a localized string similar to Legion Space Daemon is active. + /// + public static string Hint_LegionGoServices { + get { + return ResourceManager.GetString("Hint_LegionGoServices", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Disable Legion Space Daemon. + /// + public static string Hint_LegionGoServicesAction { + get { + return ResourceManager.GetString("Hint_LegionGoServicesAction", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Legion Space Daemon is already active on your console. This may cause compatibility issues with the application.. + /// + public static string Hint_LegionGoServicesDesc { + get { + return ResourceManager.GetString("Hint_LegionGoServicesDesc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You should disable Legion Space Daemon, so that the application can run properly and without any errors. + /// + public static string Hint_LegionGoServicesReadme { + get { + return ResourceManager.GetString("Hint_LegionGoServicesReadme", resourceCulture); + } + } + /// /// Looks up a localized string similar to ASUS services are running. /// diff --git a/HandheldCompanion/Properties/Resources.resx b/HandheldCompanion/Properties/Resources.resx index 15a88ba11..31a81b919 100644 --- a/HandheldCompanion/Properties/Resources.resx +++ b/HandheldCompanion/Properties/Resources.resx @@ -2673,4 +2673,16 @@ with motion input toggle, press selected button(s) to switch from enabled to dis Fan max speed override + + Legion Space Daemon is active + + + Disable Legion Space Daemon + + + Legion Space Daemon is already active on your console. This may cause compatibility issues with the application. + + + You should disable Legion Space Daemon, so that the application can run properly and without any errors + \ No newline at end of file diff --git a/HandheldCompanion/Views/Pages/NotificationsPage.xaml b/HandheldCompanion/Views/Pages/NotificationsPage.xaml index de7c55581..1eca3b82d 100644 --- a/HandheldCompanion/Views/Pages/NotificationsPage.xaml +++ b/HandheldCompanion/Views/Pages/NotificationsPage.xaml @@ -55,6 +55,7 @@ +