-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hotfix for new Legion Space update v1.0.2.5: Controller READY-byte an…
…d new DAService Hint
- Loading branch information
Showing
7 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
HandheldCompanion/Controls/Hints/Hint_LegionGoServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters