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> <PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.188</AssemblyVersion> <AssemblyVersion>0.189</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -1,12 +1,13 @@
using GHelper.Helpers; using GHelper.Helpers;
using Microsoft.Win32.TaskScheduler; using Microsoft.Win32.TaskScheduler;
using System.Diagnostics;
using System.Security.Principal; using System.Security.Principal;
public class Startup public class Startup
{ {
static string taskName = "GHelper"; static string taskName = "GHelper";
static string chargeTaskName = taskName + "Charge";
static string strExeFilePath = Application.ExecutablePath.Trim();
public static bool IsScheduled() public static bool IsScheduled()
{ {
@@ -32,7 +33,6 @@ public class Startup
{ {
try try
{ {
string strExeFilePath = Application.ExecutablePath.Trim();
string action = task.Definition.Actions.FirstOrDefault()!.ToString().Trim(); string action = task.Definition.Actions.FirstOrDefault()!.ToString().Trim();
if (!strExeFilePath.Equals(action, StringComparison.OrdinalIgnoreCase) && !File.Exists(action)) if (!strExeFilePath.Equals(action, StringComparison.OrdinalIgnoreCase) && !File.Exists(action))
{ {
@@ -41,11 +41,60 @@ public class Startup
UnSchedule(); UnSchedule();
Schedule(); Schedule();
} }
} catch (Exception ex) }
catch (Exception ex)
{ {
Logger.WriteLine($"Can't check startup task: {ex.Message}"); 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,17 +102,11 @@ public class Startup
public static void Schedule() public static void Schedule()
{ {
string strExeFilePath = Application.ExecutablePath;
if (strExeFilePath is null) return;
var userId = WindowsIdentity.GetCurrent().Name;
using (TaskDefinition td = TaskService.Instance.NewTask()) using (TaskDefinition td = TaskService.Instance.NewTask())
{ {
td.RegistrationInfo.Description = "G-Helper Auto Start"; 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); td.Actions.Add(strExeFilePath);
if (ProcessHelper.IsUserAdministrator()) if (ProcessHelper.IsUserAdministrator())
@@ -73,9 +116,6 @@ public class Startup
td.Settings.DisallowStartIfOnBatteries = false; td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero; td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
Debug.WriteLine(strExeFilePath);
Debug.WriteLine(userId);
try try
{ {
TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, td); TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, td);
@@ -87,8 +127,12 @@ public class Startup
else else
ProcessHelper.RunAsAdmin(); ProcessHelper.RunAsAdmin();
} }
Logger.WriteLine("Startup task scheduled: " + strExeFilePath);
} }
ScheduleCharge();
} }
public static void UnSchedule() public static void UnSchedule()
@@ -107,5 +151,7 @@ public class Startup
ProcessHelper.RunAsAdmin(); ProcessHelper.RunAsAdmin();
} }
} }
UnscheduleCharge();
} }
} }

View File

@@ -53,6 +53,13 @@ namespace GHelper
string action = ""; string action = "";
if (args.Length > 0) action = args[0]; if (args.Length > 0) action = args[0];
if (action == "charge")
{
BatteryLimit();
Application.Exit();
return;
}
string language = AppConfig.GetString("language"); string language = AppConfig.GetString("language");
if (language != null && language.Length > 0) if (language != null && language.Length > 0)
@@ -243,7 +250,8 @@ namespace GHelper
if (AppConfig.IsAlly()) if (AppConfig.IsAlly())
{ {
allyControl.Init(); allyControl.Init();
} else }
else
{ {
settingsForm.AutoKeyboard(); settingsForm.AutoKeyboard();
} }
@@ -328,6 +336,23 @@ namespace GHelper
Application.Exit(); 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> <value>Włącz/wyłącz ekran dotykowy</value>
</data> </data>
<data name="Touchscreen" xml:space="preserve"> <data name="Touchscreen" xml:space="preserve">
<value>Touchscreen</value> <value>Ekran dotykowy</value>
</data> </data>
<data name="Turbo" xml:space="preserve"> <data name="Turbo" xml:space="preserve">
<value>Turbo</value> <value>Turbo</value>
@@ -801,21 +801,21 @@ Nadal chcesz kontynuować?</value>
<value>Przybliżenie</value> <value>Przybliżenie</value>
</data> </data>
<data name="Donate" xml:space="preserve"> <data name="Donate" xml:space="preserve">
<value>Donate</value> <value>Wesprzyj</value>
</data> </data>
<data name="Legend" xml:space="preserve"> <data name="Legend" xml:space="preserve">
<value>Legend</value> <value>Legenda</value>
</data> </data>
<data name="LegendGray" xml:space="preserve"> <data name="LegendGray" xml:space="preserve">
<value>Can't check local version</value> <value>Brak informacji</value>
<comment>Can't check local version</comment> <comment>Can't check local version</comment>
</data> </data>
<data name="LegendRed" xml:space="preserve"> <data name="LegendRed" xml:space="preserve">
<value>Update Available</value> <value>Dostępna aktualizacja</value>
<comment>Update Available</comment> <comment>Update Available</comment>
</data> </data>
<data name="LegendGreen" xml:space="preserve"> <data name="LegendGreen" xml:space="preserve">
<value>Updated</value> <value>Wersja aktualna</value>
<comment>Updated</comment> <comment>Updated</comment>
</data> </data>
</root> </root>

View File

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