-
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.
- Loading branch information
Showing
12 changed files
with
413 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ labels: bug | |
- [ ] GPD | ||
- [ ] ONEXPLAYER | ||
- [ ] VALVE | ||
- [ ] LENOVO | ||
|
||
**Device model** | ||
Your device model | ||
|
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
60 changes: 60 additions & 0 deletions
60
HandheldCompanion/Controls/Hints/Hint_HWiNFO12hLimitPassed.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,60 @@ | ||
using HandheldCompanion.Managers; | ||
using HandheldCompanion.Platforms; | ||
using System; | ||
using System.Windows; | ||
|
||
namespace HandheldCompanion.Controls.Hints | ||
{ | ||
public class Hint_HWiNFO12hLimitPassed : IHint | ||
{ | ||
public Hint_HWiNFO12hLimitPassed() : base() | ||
{ | ||
PlatformManager.HWiNFO.Updated += HWiNFO_Updated; | ||
PlatformManager.HWiNFO.SettingValueChanged += HWiNFO_SettingValueChanged; | ||
|
||
PlatformManager.Initialized += PlatformManager_Initialized; | ||
|
||
// default state | ||
this.HintActionButton.Visibility = Visibility.Collapsed; | ||
|
||
this.HintTitle.Text = Properties.Resources.Hint_HWiNFO12hLimitPassed; | ||
this.HintDescription.Text = Properties.Resources.Hint_HWiNFO12hLimitPassedDesc; | ||
this.HintReadMe.Text = Properties.Resources.Hint_HWiNFO12hLimitPassedReadme; | ||
} | ||
|
||
private void HWiNFO_Updated(PlatformStatus status) | ||
{ | ||
CheckSettings(); | ||
} | ||
|
||
private void HWiNFO_SettingValueChanged(string name, object value) | ||
{ | ||
// UI thread (async) | ||
Application.Current.Dispatcher.BeginInvoke(() => | ||
{ | ||
switch(name) | ||
{ | ||
case "SensorsSM": | ||
this.Visibility = Convert.ToBoolean(value) ? Visibility.Collapsed : Visibility.Visible; | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
private void PlatformManager_Initialized() | ||
{ | ||
CheckSettings(); | ||
} | ||
|
||
private void CheckSettings() | ||
{ | ||
bool SensorsSM = PlatformManager.HWiNFO.GetProperty("SensorsSM"); | ||
HWiNFO_SettingValueChanged("SensorsSM", SensorsSM); | ||
} | ||
|
||
public override void 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using HandheldCompanion.Devices; | ||
using HandheldCompanion.Views; | ||
using Microsoft.Win32.TaskScheduler; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Timers; | ||
using System.Windows; | ||
using Task = System.Threading.Tasks.Task; | ||
|
||
namespace HandheldCompanion.Controls.Hints | ||
{ | ||
public class Hint_LegionGoDaemon : IHint | ||
{ | ||
private Process process; | ||
private const string taskName = "LSDaemon"; | ||
private Timer taskTimer; | ||
|
||
public Hint_LegionGoDaemon() : base() | ||
{ | ||
if (MainWindow.CurrentDevice is not LegionGo) | ||
return; | ||
|
||
taskTimer = new Timer(4000); | ||
taskTimer.Elapsed += TaskTimer_Elapsed; | ||
taskTimer.Start(); | ||
|
||
// default state | ||
this.HintActionButton.Visibility = Visibility.Visible; | ||
|
||
this.HintTitle.Text = Properties.Resources.Hint_LegionGoDaemon; | ||
this.HintDescription.Text = Properties.Resources.Hint_LegionGoDaemonDesc; | ||
this.HintReadMe.Text = Properties.Resources.Hint_LegionGoDaemonReadme; | ||
|
||
this.HintActionButton.Content = Properties.Resources.Hint_LegionGoDaemonAction; | ||
} | ||
|
||
private void TaskTimer_Elapsed(object? sender, ElapsedEventArgs e) | ||
{ | ||
// Get all the processes with the given name | ||
process = Process.GetProcessesByName(taskName).FirstOrDefault(); | ||
|
||
// If there is at least one process, return true | ||
// UI thread (async) | ||
Application.Current.Dispatcher.BeginInvoke(() => | ||
{ | ||
if (process is not null && !process.HasExited) | ||
this.Visibility = Visibility.Visible; | ||
else | ||
this.Visibility = Visibility.Collapsed; | ||
}); | ||
} | ||
|
||
protected override void HintActionButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
Task.Run(async () => | ||
{ | ||
// Get the task service instance | ||
using (TaskService ts = new TaskService()) | ||
{ | ||
// Get the task by name | ||
Microsoft.Win32.TaskScheduler.Task task = ts.GetTask(taskName); | ||
if (task != null && task.State == TaskState.Running) | ||
{ | ||
task.Stop(); | ||
task.Enabled = false; | ||
} | ||
} | ||
}); | ||
|
||
// If the process exists and is running, kill it | ||
if (process != null && !process.HasExited) | ||
process.Kill(); | ||
} | ||
|
||
public override void Stop() | ||
{ | ||
taskTimer.Stop(); | ||
base.Stop(); | ||
} | ||
} | ||
} |
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
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
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
Binary file not shown.
Binary file not shown.
Oops, something went wrong.