Compare commits

..

6 Commits

Author SHA1 Message Date
Serge
ffd9bf6673 Cleanup 2024-09-09 13:09:30 +02:00
Serge
80f61912f3 Version bump 2024-09-09 13:07:31 +02:00
Serge
2833373f9e System Startup charge limiter 2024-09-09 13:01:34 +02:00
Serge
cf94973419 Merge branch 'main' of https://github.com/seerge/g-helper 2024-09-09 12:33:24 +02:00
Serge
421dc0c05c System Startup charge limiter 2024-09-09 12:33:22 +02:00
Serge
38965bad9f New Crowdin updates (#3081)
* New translations strings.resx (Polish)

* New translations strings.resx (Chinese Traditional)
2024-09-09 09:53:13 +02:00
5 changed files with 101 additions and 30 deletions

View File

@@ -15,7 +15,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.188</AssemblyVersion>
<AssemblyVersion>0.189</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -1,12 +1,13 @@
using GHelper.Helpers;
using Microsoft.Win32.TaskScheduler;
using System.Diagnostics;
using System.Security.Principal;
public class Startup
{
static string taskName = "GHelper";
static string chargeTaskName = taskName + "Charge";
static string strExeFilePath = Application.ExecutablePath.Trim();
public static bool IsScheduled()
{
@@ -32,7 +33,6 @@ public class Startup
{
try
{
string strExeFilePath = Application.ExecutablePath.Trim();
string action = task.Definition.Actions.FirstOrDefault()!.ToString().Trim();
if (!strExeFilePath.Equals(action, StringComparison.OrdinalIgnoreCase) && !File.Exists(action))
{
@@ -41,11 +41,60 @@ public class Startup
UnSchedule();
Schedule();
}
} catch (Exception ex)
}
catch (Exception ex)
{
Logger.WriteLine($"Can't check startup task: {ex.Message}");
}
if (taskService.RootFolder.AllTasks.FirstOrDefault(t => t.Name == chargeTaskName) == null) ScheduleCharge();
}
}
}
public static void UnscheduleCharge()
{
using (TaskService taskService = new TaskService())
{
try
{
taskService.RootFolder.DeleteTask(chargeTaskName);
}
catch (Exception e)
{
Logger.WriteLine("Can't remove charge limit task: " + e.Message);
}
}
}
public static void ScheduleCharge()
{
if (strExeFilePath is null) return;
using (TaskDefinition td = TaskService.Instance.NewTask())
{
td.RegistrationInfo.Description = "G-Helper Charge Limit";
td.Triggers.Add(new BootTrigger());
td.Actions.Add(strExeFilePath, "charge");
td.Principal.RunLevel = TaskRunLevel.LUA;
td.Principal.LogonType = TaskLogonType.S4U;
td.Principal.UserId = WindowsIdentity.GetCurrent().Name;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
try
{
TaskService.Instance.RootFolder.RegisterTaskDefinition(chargeTaskName, td);
Logger.WriteLine("Charge limit task scheduled: " + strExeFilePath);
}
catch (Exception e)
{
Logger.WriteLine("Can't create a charge limit task: " + e.Message);
}
}
}
@@ -53,29 +102,20 @@ public class Startup
public static void Schedule()
{
string strExeFilePath = Application.ExecutablePath;
if (strExeFilePath is null) return;
var userId = WindowsIdentity.GetCurrent().Name;
using (TaskDefinition td = TaskService.Instance.NewTask())
{
td.RegistrationInfo.Description = "G-Helper Auto Start";
td.Triggers.Add(new LogonTrigger { UserId = userId, Delay = TimeSpan.FromSeconds(1) });
td.Triggers.Add(new LogonTrigger { UserId = WindowsIdentity.GetCurrent().Name, Delay = TimeSpan.FromSeconds(1) });
td.Actions.Add(strExeFilePath);
if (ProcessHelper.IsUserAdministrator())
if (ProcessHelper.IsUserAdministrator())
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
Debug.WriteLine(strExeFilePath);
Debug.WriteLine(userId);
try
{
TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, td);
@@ -87,8 +127,12 @@ public class Startup
else
ProcessHelper.RunAsAdmin();
}
Logger.WriteLine("Startup task scheduled: " + strExeFilePath);
}
ScheduleCharge();
}
public static void UnSchedule()
@@ -107,5 +151,7 @@ public class Startup
ProcessHelper.RunAsAdmin();
}
}
UnscheduleCharge();
}
}

View File

@@ -53,6 +53,13 @@ namespace GHelper
string action = "";
if (args.Length > 0) action = args[0];
if (action == "charge")
{
BatteryLimit();
Application.Exit();
return;
}
string language = AppConfig.GetString("language");
if (language != null && language.Length > 0)
@@ -205,7 +212,7 @@ namespace GHelper
if (settingsForm.matrixForm is not null && settingsForm.matrixForm.Text != "")
settingsForm.matrixForm.InitTheme();
if (settingsForm.handheldForm is not null && settingsForm.handheldForm.Text != "")
if (settingsForm.handheldForm is not null && settingsForm.handheldForm.Text != "")
settingsForm.handheldForm.InitTheme();
break;
@@ -243,7 +250,8 @@ namespace GHelper
if (AppConfig.IsAlly())
{
allyControl.Init();
} else
}
else
{
settingsForm.AutoKeyboard();
}
@@ -288,7 +296,7 @@ namespace GHelper
}
else
{
var screen = Screen.PrimaryScreen;
var screen = Screen.PrimaryScreen;
if (screen is null) screen = Screen.FromControl(settingsForm);
settingsForm.Location = screen.WorkingArea.Location;
@@ -299,7 +307,7 @@ namespace GHelper
settingsForm.Activate();
settingsForm.Left = screen.WorkingArea.Width - 10 - settingsForm.Width;
if (AppConfig.IsAlly())
settingsForm.Top = Math.Max(10, screen.Bounds.Height - 110 - settingsForm.Height);
else
@@ -328,6 +336,23 @@ namespace GHelper
Application.Exit();
}
static void BatteryLimit()
{
try
{
int limit = AppConfig.Get("charge_limit");
if (limit > 0 && limit < 100)
{
Logger.WriteLine($"------- Startup Battery Limit {limit} -------");
acpi = new AsusACPI();
acpi.DeviceSet(AsusACPI.BatteryLimit, limit, "Limit");
}
}
catch (Exception ex)
{
Logger.WriteLine("Startup Battery Limit Error: " + ex.Message);
}
}
}
}

View File

@@ -744,7 +744,7 @@ Nadal chcesz kontynuować?</value>
<value>Włącz/wyłącz ekran dotykowy</value>
</data>
<data name="Touchscreen" xml:space="preserve">
<value>Touchscreen</value>
<value>Ekran dotykowy</value>
</data>
<data name="Turbo" xml:space="preserve">
<value>Turbo</value>
@@ -801,21 +801,21 @@ Nadal chcesz kontynuować?</value>
<value>Przybliżenie</value>
</data>
<data name="Donate" xml:space="preserve">
<value>Donate</value>
<value>Wesprzyj</value>
</data>
<data name="Legend" xml:space="preserve">
<value>Legend</value>
<value>Legenda</value>
</data>
<data name="LegendGray" xml:space="preserve">
<value>Can't check local version</value>
<value>Brak informacji</value>
<comment>Can't check local version</comment>
</data>
<data name="LegendRed" xml:space="preserve">
<value>Update Available</value>
<value>Dostępna aktualizacja</value>
<comment>Update Available</comment>
</data>
<data name="LegendGreen" xml:space="preserve">
<value>Updated</value>
<value>Wersja aktualna</value>
<comment>Updated</comment>
</data>
</root>

View File

@@ -744,7 +744,7 @@
<value>切換螢幕觸控</value>
</data>
<data name="Touchscreen" xml:space="preserve">
<value>Touchscreen</value>
<value>觸控螢幕</value>
</data>
<data name="Turbo" xml:space="preserve">
<value>極速</value>
@@ -801,21 +801,21 @@
<value>縮放</value>
</data>
<data name="Donate" xml:space="preserve">
<value>Donate</value>
<value>捐贈</value>
</data>
<data name="Legend" xml:space="preserve">
<value>Legend</value>
</data>
<data name="LegendGray" xml:space="preserve">
<value>Can't check local version</value>
<value>無法檢查本機版本</value>
<comment>Can't check local version</comment>
</data>
<data name="LegendRed" xml:space="preserve">
<value>Update Available</value>
<value>有可用的更新</value>
<comment>Update Available</comment>
</data>
<data name="LegendGreen" xml:space="preserve">
<value>Updated</value>
<value>已更新</value>
<comment>Updated</comment>
</data>
</root>