Send notification on performance mode cycling

This commit is contained in:
Albert24GG
2023-02-21 22:51:52 +02:00
parent 81a0019b42
commit c705ce2b5b
2 changed files with 35 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows10.0.17763.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWindowsForms>True</UseWindowsForms> <UseWindowsForms>True</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
@@ -31,6 +31,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="hidlibrary" Version="3.3.40" /> <PackageReference Include="hidlibrary" Version="3.3.40" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="System.Management" Version="7.0.0" /> <PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" /> <PackageReference Include="TaskScheduler" Version="2.10.1" />
</ItemGroup> </ItemGroup>

View File

@@ -3,6 +3,8 @@ using System.Diagnostics;
using System.Management; using System.Management;
using System.Timers; using System.Timers;
using System.Windows.Forms; using System.Windows.Forms;
using Windows.UI.Notifications;
using Microsoft.Toolkit.Uwp.Notifications;
namespace GHelper namespace GHelper
{ {
@@ -331,28 +333,37 @@ namespace GHelper
buttonBalanced.FlatAppearance.BorderSize = buttonInactive; buttonBalanced.FlatAppearance.BorderSize = buttonInactive;
buttonTurbo.FlatAppearance.BorderSize = buttonInactive; buttonTurbo.FlatAppearance.BorderSize = buttonInactive;
string[] mode = new string[]{
"Balanced",
"Turbo",
"Silent"
};
switch (PerformanceMode) switch (PerformanceMode)
{ {
case ASUSWmi.PerformanceSilent: case ASUSWmi.PerformanceSilent:
buttonSilent.FlatAppearance.BorderSize = buttonActive; buttonSilent.FlatAppearance.BorderSize = buttonActive;
labelPerf.Text = "Performance Mode: Silent";
break; break;
case ASUSWmi.PerformanceTurbo: case ASUSWmi.PerformanceTurbo:
buttonTurbo.FlatAppearance.BorderSize = buttonActive; buttonTurbo.FlatAppearance.BorderSize = buttonActive;
labelPerf.Text = "Performance Mode: Turbo";
break; break;
default: default:
buttonBalanced.FlatAppearance.BorderSize = buttonActive; buttonBalanced.FlatAppearance.BorderSize = buttonActive;
labelPerf.Text = "Performance Mode: Balanced";
PerformanceMode = ASUSWmi.PerformanceBalanced; PerformanceMode = ASUSWmi.PerformanceBalanced;
break; break;
} }
labelPerf.Text = "Performance Mode: " + mode[PerformanceMode];
string notifTitle = "Performance Mode Changed";
string notifBody = "Switched to: " + mode[PerformanceMode];
Program.config.setConfig("performance_mode", PerformanceMode); Program.config.setConfig("performance_mode", PerformanceMode);
try try
{ {
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode); Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
if(notify)
sendNotification(notifTitle, notifBody);
} catch } catch
{ {
labelPerf.Text = "Performance Mode: not supported"; labelPerf.Text = "Performance Mode: not supported";
@@ -363,9 +374,27 @@ namespace GHelper
public void CyclePerformanceMode() public void CyclePerformanceMode()
{ {
SetPerformanceMode(Program.config.getConfig("performance_mode") + 1); SetPerformanceMode(Program.config.getConfig("performance_mode") + 1, true);
} }
public void sendNotification(string title, string message)
{
var content = new ToastContentBuilder()
.AddText(title)
.AddText(message)
.SetToastDuration(ToastDuration.Short)
.GetToastContent();
var notification = new ToastNotification(content.GetXml())
{
Priority = ToastNotificationPriority.High
};
ToastNotificationManagerCompat.CreateToastNotifier().Show(notification);
}
public void AutoScreen(int Plugged = 1) public void AutoScreen(int Plugged = 1)
{ {
int ScreenAuto = Program.config.getConfig("screen_auto"); int ScreenAuto = Program.config.getConfig("screen_auto");