Skip to content

Commit

Permalink
Merge branch 'main' into cpu-auto-tdp
Browse files Browse the repository at this point in the history
  • Loading branch information
IceStormNG committed Jan 18, 2025
2 parents 6bf3d04 + 1254c4c commit 8f48af4
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 31 deletions.
12 changes: 8 additions & 4 deletions app/Ally/AllyControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ public class AllyControl
public const string BindBrightnessUp = "04-04-8C-88-8A-06";
public const string BindXGM = "04-04-8C-88-8A-04";
public const string BindToggleMode = "04-04-8C-88-8A-0C";
public const string BindToggleTouchScreen = "04-04-8C-88-8A-0B";

public const string BindOverlay = "04-03-8C-88-44";

public const string BindShiftTab = "04-02-88-0D";
public const string BindAltTab = "04-02-8A-0D";
public const string BindWinTab = "04-02-82-0D";

public const string BindVolUp = "05-03";
public const string BindVolDown = "05-02";
Expand Down Expand Up @@ -156,6 +158,7 @@ public class AllyControl
{ BindXB, "XBox/Steam" },

{ BindToggleMode, "Controller Mode" },
{ BindToggleTouchScreen, "Toggle TouchScreen" },

{ BindVolUp, "Vol Up" },
{ BindVolDown, "Vol Down" },
Expand All @@ -171,6 +174,7 @@ public class AllyControl
{ BindCloseWindow, "Close Window" },
{ BindShiftTab, "Shift-Tab" },
{ BindAltTab, "Alt-Tab" },
{ BindWinTab, "Win-Tab" },
{ BindXGM, "XGM Toggle" },


Expand Down Expand Up @@ -566,10 +570,10 @@ static private void BindZone(BindingZone zone)
KeyR2 = AppConfig.GetString("bind2_m1", BindM1);
break;
default:
KeyL1 = AppConfig.GetString("bind_trl", desktop ? BindShiftTab : BindLT);
KeyR1 = AppConfig.GetString("bind_trr", desktop ? BindMouseR : BindRT);
KeyL2 = AppConfig.GetString("bind2_trl");
KeyR2 = AppConfig.GetString("bind2_trr");
KeyL1 = AppConfig.GetString("bind_lt", desktop ? BindShiftTab : BindLT);
KeyR1 = AppConfig.GetString("bind_rt", desktop ? BindMouseR : BindRT);
KeyL2 = AppConfig.GetString("bind2_lt");
KeyR2 = AppConfig.GetString("bind2_rt");
break;
}

Expand Down
7 changes: 6 additions & 1 deletion app/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public static bool SwappedBrightness()

public static bool IsDUO()
{
return ContainsModel("Duo") || ContainsModel("GX550") || ContainsModel("GX650") || ContainsModel("UX840");
return ContainsModel("Duo") || ContainsModel("GX550") || ContainsModel("GX650") || ContainsModel("UX840") || ContainsModel("UX482");
}

// G14 2020 has no aura, but media keys instead
Expand Down Expand Up @@ -679,6 +679,11 @@ public static bool IsIntelHX()
return ContainsModel("G814") || ContainsModel("G614") || ContainsModel("G834") || ContainsModel("G634");
}

public static bool Is8Ecores()
{
return ContainsModel("FX507ZU");
}

public static bool IsNoFNV()
{
return ContainsModel("FX507") || ContainsModel("FX707");
Expand Down
28 changes: 25 additions & 3 deletions app/AutoUpdate/AutoUpdateControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net;
using System.Reflection;
using System.Text.Json;
using System.Text.RegularExpressions;

namespace GHelper.AutoUpdate
{
Expand Down Expand Up @@ -39,7 +40,8 @@ public void LoadReleases()
try
{
Process.Start(new ProcessStartInfo(versionUrl) { UseShellExecute = true });
} catch (Exception ex)
}
catch (Exception ex)
{
Logger.WriteLine("Failed to open releases page:" + ex.Message);
}
Expand Down Expand Up @@ -81,6 +83,13 @@ async void CheckForUpdatesAsync()
versionUrl = url;
settings.SetVersionLabel(Properties.Strings.DownloadUpdate + ": " + tag, true);

string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1 && args[1] == "autoupdate")
{
AutoUpdate(url);
return;
}

if (AppConfig.GetString("skip_version") != tag)
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.DownloadUpdate + ": G-Helper " + tag + "?", "Update", MessageBoxButtons.YesNo);
Expand All @@ -105,6 +114,10 @@ async void CheckForUpdatesAsync()

}

public static string EscapeString(string input)
{
return Regex.Replace(Regex.Replace(input, @"\[|\]", "`$0"), @"\'", "''");
}

async void AutoUpdate(string requestUri)
{
Expand All @@ -114,19 +127,28 @@ async void AutoUpdate(string requestUri)

string exeLocation = Application.ExecutablePath;
string exeDir = Path.GetDirectoryName(exeLocation);
//exeDir = "C:\\Program Files\\GHelper";
string exeName = Path.GetFileName(exeLocation);
string zipLocation = exeDir + "\\" + zipName;

using (WebClient client = new WebClient())
{
client.DownloadFile(uri, zipLocation);
try
{
client.DownloadFile(uri, zipLocation);
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
ProcessHelper.RunAsAdmin("autoupdate");
}

Logger.WriteLine(requestUri);
Logger.WriteLine(exeDir);
Logger.WriteLine(zipName);
Logger.WriteLine(exeName);

string command = $"$ErrorActionPreference = \"Stop\"; Wait-Process -Name \"GHelper\"; Expand-Archive \"{zipName}\" -DestinationPath . -Force; Remove-Item \"{zipName}\" -Force; \".\\{exeName}\"; ";
string command = $"$ErrorActionPreference = \"Stop\"; Set-Location -Path '{EscapeString(exeDir)}'; Wait-Process -Name \"GHelper\"; Expand-Archive \"{zipName}\" -DestinationPath . -Force; Remove-Item \"{zipName}\" -Force; \".\\{exeName}\"; ";
Logger.WriteLine(command);

try
Expand Down
17 changes: 17 additions & 0 deletions app/Display/ScreenControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ public void InitMiniled()
SetMiniled(AppConfig.Get("miniled"));
}

public void InitOptimalBrightness()
{
int optimalBrightness = AppConfig.Get("optimal_brightness");
if (optimalBrightness >= 0) SetOptimalBrightness(optimalBrightness);
}

public void SetOptimalBrightness(int status)
{
Program.acpi.DeviceSet(AsusACPI.ScreenOptimalBrightness, status, "Optimal Brightness");
AppConfig.Set("optimal_brightness", status);
}

public int GetOptimalBrightness()
{
return Program.acpi.DeviceGet(AsusACPI.ScreenOptimalBrightness);
}

public void ToogleFHD()
{
int fhd = Program.acpi.DeviceGet(AsusACPI.ScreenFHD);
Expand Down
4 changes: 3 additions & 1 deletion app/Display/VisualControl.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GHelper.Helpers;
using Microsoft.Win32;
using Ryzen;
using System.Management;

namespace GHelper.Display
Expand Down Expand Up @@ -252,7 +253,8 @@ public static void SetGamut(int mode = -1)
public static void SetVisual(SplendidCommand mode = SplendidCommand.Default, int whiteBalance = DefaultColorTemp, bool init = false)
{
if (mode == SplendidCommand.None) return;
if ((mode == SplendidCommand.Disabled || mode == SplendidCommand.Default || mode == SplendidCommand.VivoNormal) && init) return; // Skip default setting on init
if ((mode == SplendidCommand.Default || mode == SplendidCommand.VivoNormal) && init) return; // Skip default setting on init
if (mode == SplendidCommand.Disabled && !RyzenControl.IsAMD() && init) return; // Skip disabled setting for Intel devices

if (!forceVisual && ScreenCCD.GetHDRStatus(true)) return;
if (!forceVisual && ScreenNative.GetRefreshRate(ScreenNative.FindLaptopScreen(true)) < 0) return;
Expand Down
15 changes: 13 additions & 2 deletions app/Extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public Extra()
labelFNF4.Visible = comboFNF4.Visible = textFNF4.Visible = false;
}

if (AppConfig.IsVivoZenPro())
{
labelM1.Visible = comboM1.Visible = textM1.Visible = false;
labelM2.Visible = comboM2.Visible = textM2.Visible = false;
labelM3.Visible = comboM3.Visible = textM3.Visible = false;
labelFNF4.Visible = comboFNF4.Visible = textFNF4.Visible = false;
labelM4.Text = "FN+F12";
}

if (AppConfig.MediaKeys())
{
labelFNF4.Visible = comboFNF4.Visible = textFNF4.Visible = false;
Expand Down Expand Up @@ -425,7 +434,7 @@ public Extra()
checkStatusLed.Checked = (statusLed > 0);
checkStatusLed.CheckedChanged += CheckLEDStatus_CheckedChanged;

var optimalBrightness = Program.acpi.DeviceGet(AsusACPI.ScreenOptimalBrightness);
var optimalBrightness = screenControl.GetOptimalBrightness();
checkOptimalBrightness.Visible = optimalBrightness >= 0;
checkOptimalBrightness.Checked = (optimalBrightness > 0);
checkOptimalBrightness.CheckedChanged += CheckOptimalBrightness_CheckedChanged;
Expand Down Expand Up @@ -460,7 +469,7 @@ public Extra()

private void CheckOptimalBrightness_CheckedChanged(object? sender, EventArgs e)
{
Program.acpi.DeviceSet(AsusACPI.ScreenOptimalBrightness, checkOptimalBrightness.Checked ? 1 : 0, "Optimal Brightness");
screenControl.SetOptimalBrightness(checkOptimalBrightness.Checked ? 1 : 0);
}

private void CheckPerKeyRGB_CheckedChanged(object? sender, EventArgs e)
Expand Down Expand Up @@ -520,6 +529,8 @@ private void InitCores()
if (eCoresMax == 0) eCoresMax = 8;
if (pCoresMax == 0) pCoresMax = 6;

if (AppConfig.Is8Ecores()) eCoresMax = Math.Max(8, eCoresMax);

eCoresMax = Math.Max(4, eCoresMax);
pCoresMax = Math.Max(6, pCoresMax);

Expand Down
2 changes: 1 addition & 1 deletion app/GHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.200</AssemblyVersion>
<AssemblyVersion>0.202</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
39 changes: 25 additions & 14 deletions app/Input/InputDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void RegisterKeys()
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, Keys.F20);
}

if (!AppConfig.IsZ13() && !AppConfig.IsAlly())
if (!AppConfig.IsZ13() && !AppConfig.IsAlly() && !AppConfig.IsVivoZenPro())
{
if (actionM1 is not null && actionM1.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeDown);
if (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp);
Expand All @@ -164,6 +164,7 @@ public void RegisterKeys()
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F2);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F3);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F4);
hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F6);
}

// FN-Lock group
Expand Down Expand Up @@ -456,6 +457,9 @@ public void KeyPressed(object sender, KeyPressedEventArgs e)
case Keys.F4:
Program.settingsForm.BeginInvoke(Program.settingsForm.allyControl.ToggleModeHotkey);
break;
case Keys.F6:
ToggleTouchScreen();
break;
case Keys.F7:
SetScreenpad(-10);
break;
Expand Down Expand Up @@ -605,20 +609,25 @@ public static void KeyProcess(string name = "m3")
Program.settingsForm.BeginInvoke(Program.settingsForm.allyControl.ToggleModeHotkey);
break;
case "touchscreen":
var status = !TouchscreenHelper.GetStatus();
Logger.WriteLine("Touchscreen status: " + status);
if (status is not null)
{
Program.toast.RunToast(Properties.Strings.Touchscreen + " " + ((bool)status ? Properties.Strings.On : Properties.Strings.Off), ToastIcon.Touchpad);
TouchscreenHelper.ToggleTouchscreen((bool)status);
}
ToggleTouchScreen();
break;
default:
break;
}
}


static void ToggleTouchScreen()
{
var status = !TouchscreenHelper.GetStatus();
Logger.WriteLine("Touchscreen status: " + status);
if (status is not null)
{
Program.toast.RunToast(Properties.Strings.Touchscreen + " " + ((bool)status ? Properties.Strings.On : Properties.Strings.Off), ToastIcon.Touchpad);
TouchscreenHelper.ToggleTouchscreen((bool)status);
}
}

static void ToggleMic()
{
bool muteStatus = Audio.ToggleMute();
Expand Down Expand Up @@ -889,14 +898,15 @@ public static void AutoKeyboard()
Aura.Init();
Aura.ApplyPower();
Aura.ApplyAura();
SetBacklightAuto();
SetBacklightAuto(true);
}


public static void SetBacklightAuto()
public static void SetBacklightAuto(bool init = false)
{
if (lidClose) return;
Aura.ApplyBrightness(GetBacklight(), "Auto");
if (init) Aura.Init();
Aura.ApplyBrightness(GetBacklight(), "Auto", init);
}

public static void SetBacklight(int delta, bool force = false)
Expand All @@ -906,11 +916,12 @@ public static void SetBacklight(int delta, bool force = false)
bool onBattery = SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online;

int backlight = onBattery ? backlight_battery : backlight_power;
int backlightMax = AppConfig.Get("max_brightness", 3);

if (delta >= 4)
backlight = ++backlight % 4;
if (delta > backlightMax)
backlight = ++backlight % (backlightMax + 1);
else
backlight = Math.Max(Math.Min(3, backlight + delta), 0);
backlight = Math.Max(Math.Min(backlightMax, backlight + delta), 0);

if (onBattery)
AppConfig.Set("keyboard_brightness_ac", backlight);
Expand Down
8 changes: 3 additions & 5 deletions app/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ public static bool SetAutoModes(bool powerChanged = false, bool init = false)
Logger.WriteLine("AutoSetting for " + isPlugged.ToString());

BatteryControl.AutoBattery(init);
if (init)
{
InputDispatcher.InitScreenpad();
}
if (init) InputDispatcher.InitScreenpad();
screenControl.InitOptimalBrightness();

inputDispatcher.Init();

Expand Down Expand Up @@ -275,7 +273,7 @@ public static bool SetAutoModes(bool powerChanged = false, bool init = false)

private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{

Logger.WriteLine($"Power Mode {e.Mode}: {SystemInformation.PowerStatus.PowerLineStatus}");
if (e.Mode == PowerModes.Suspend)
{
Logger.WriteLine("Power Mode Changed:" + e.Mode.ToString());
Expand Down

0 comments on commit 8f48af4

Please sign in to comment.