mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Update checker fixes
This commit is contained in:
@@ -90,7 +90,7 @@ namespace Starlight.AnimeMatrix
|
||||
MaxColumns = 33;
|
||||
|
||||
FullRows = 7;
|
||||
FullEvenRows = 1;
|
||||
FullEvenRows = 3;
|
||||
|
||||
MaxRows = 55;
|
||||
LedCount = 1214;
|
||||
@@ -151,7 +151,11 @@ namespace Starlight.AnimeMatrix
|
||||
|
||||
public int XEnd(int row)
|
||||
{
|
||||
if (row <= FullEvenRows && row % 2 == 0) return MaxColumns - 1;
|
||||
if (row <= FullEvenRows)
|
||||
{
|
||||
if (row % 2 == 1) return MaxColumns + 2;
|
||||
else return MaxColumns;
|
||||
}
|
||||
return MaxColumns;
|
||||
}
|
||||
|
||||
@@ -196,7 +200,7 @@ namespace Starlight.AnimeMatrix
|
||||
{
|
||||
EnsureRowInRange(y);
|
||||
var start = RowToLinearAddress(y) - XStart(y);
|
||||
if (x >= XStart(y) && x < XEnd(y))
|
||||
if (x >= XStart(y) && x < MaxColumns)
|
||||
{
|
||||
SetLedLinear(start + x, value);
|
||||
}
|
||||
@@ -325,11 +329,13 @@ namespace Starlight.AnimeMatrix
|
||||
using (Bitmap bmp = new Bitmap(canvas, MaxColumns * 2, MaxRows))
|
||||
{
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < bmp.Width; x++)
|
||||
if (x % 2 == y % 2)
|
||||
{
|
||||
var pixel = bmp.GetPixel(x, y);
|
||||
SetLedPlanar(x / 2, y, (byte)((pixel.R + pixel.G + pixel.B)/3));
|
||||
SetLedPlanar(x / 2, y, (byte)((pixel.R + pixel.G + pixel.B) / 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ public static class ControlHelper
|
||||
{
|
||||
|
||||
static bool _invert = false;
|
||||
static bool _resize = false;
|
||||
static bool _darkTheme = false;
|
||||
|
||||
static float _scale = 1;
|
||||
|
||||
@@ -20,11 +20,13 @@ public static class ControlHelper
|
||||
public static void Adjust(RForm container, bool darkTheme = false, bool invert = false)
|
||||
{
|
||||
|
||||
_darkTheme = darkTheme;
|
||||
|
||||
if (darkTheme)
|
||||
{
|
||||
formBack = Color.FromArgb(255, 35, 35, 35);
|
||||
backMain = Color.FromArgb(255, 50, 50, 50);
|
||||
foreMain = Color.White;
|
||||
foreMain = Color.FromArgb(255, 240, 240, 240);
|
||||
foreAccent = Color.FromArgb(255, 100, 100, 100);
|
||||
borderMain = Color.FromArgb(255, 50, 50, 50);
|
||||
buttonMain = Color.FromArgb(255, 80, 80, 80);
|
||||
@@ -115,8 +117,6 @@ public static class ControlHelper
|
||||
{
|
||||
chart.BackColor = backMain;
|
||||
chart.ChartAreas[0].BackColor = backMain;
|
||||
chart.ChartAreas[0].AxisX.MajorGrid.LineColor = foreAccent;
|
||||
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = foreAccent;
|
||||
|
||||
chart.ChartAreas[0].AxisX.TitleForeColor = foreMain;
|
||||
chart.ChartAreas[0].AxisY.TitleForeColor = foreMain;
|
||||
@@ -127,6 +127,8 @@ public static class ControlHelper
|
||||
chart.ChartAreas[0].AxisX.MajorTickMark.LineColor = foreMain;
|
||||
chart.ChartAreas[0].AxisY.MajorTickMark.LineColor = foreMain;
|
||||
|
||||
chart.ChartAreas[0].AxisX.MajorGrid.LineColor = foreAccent;
|
||||
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = foreAccent;
|
||||
chart.ChartAreas[0].AxisX.LineColor = foreAccent;
|
||||
chart.ChartAreas[0].AxisY.LineColor = foreAccent;
|
||||
|
||||
|
||||
@@ -47,6 +47,13 @@ namespace GHelper
|
||||
|
||||
chart.ChartAreas[0].AxisY.LabelStyle.Font = new Font("Arial", 7F);
|
||||
|
||||
var foreAccent = Color.FromArgb(255, 100, 100, 100);
|
||||
|
||||
chart.ChartAreas[0].AxisX.MajorGrid.LineColor = foreAccent;
|
||||
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = foreAccent;
|
||||
chart.ChartAreas[0].AxisX.LineColor = foreAccent;
|
||||
chart.ChartAreas[0].AxisY.LineColor = foreAccent;
|
||||
|
||||
for (int i = 0; i <= 90; i += 10)
|
||||
chart.ChartAreas[0].AxisY.CustomLabels.Add(i - 2, i + 2, ChartPercToRPM(i));
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<AssemblyVersion>0.37</AssemblyVersion>
|
||||
<AssemblyVersion>0.38</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -46,15 +46,17 @@ public static class HardwareMonitor
|
||||
|
||||
}
|
||||
|
||||
public static void RecreateGpuTemperatureProviderWithRetry() {
|
||||
RecreateGpuTemperatureProvider();
|
||||
public static void RecreateGpuTemperatureProviderWithDelay() {
|
||||
|
||||
// Re-enabling the discrete GPU takes a bit of time,
|
||||
// so a simple workaround is to refresh again after that happens
|
||||
Task.Run(async () => {
|
||||
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
RecreateGpuTemperatureProvider();
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void RecreateGpuTemperatureProvider() {
|
||||
|
||||
@@ -78,9 +78,6 @@ namespace GHelper
|
||||
// Subscribing for system power change events
|
||||
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
||||
|
||||
settingsForm.SetVersionLabel("Version: " + Assembly.GetExecutingAssembly().GetName().Version);
|
||||
CheckForUpdates();
|
||||
|
||||
|
||||
if (Environment.CurrentDirectory.Trim('\\') == Application.StartupPath.Trim('\\'))
|
||||
{
|
||||
@@ -103,7 +100,7 @@ namespace GHelper
|
||||
{
|
||||
case UserPreferenceCategory.General:
|
||||
Debug.WriteLine("Theme Changed");
|
||||
Thread.Sleep(500);
|
||||
Thread.Sleep(1000);
|
||||
settingsForm.InitTheme(false);
|
||||
|
||||
if (settingsForm.fans is not null && settingsForm.fans.Text != "")
|
||||
@@ -117,39 +114,6 @@ namespace GHelper
|
||||
}
|
||||
|
||||
|
||||
static async void CheckForUpdates()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", "C# App");
|
||||
var json = await httpClient.GetStringAsync("https://api.github.com/repos/seerge/g-helper/releases/latest");
|
||||
var config = JsonSerializer.Deserialize<JsonElement>(json);
|
||||
var tag = config.GetProperty("tag_name").ToString().Replace("v", "");
|
||||
var url = config.GetProperty("assets")[0].GetProperty("browser_download_url").ToString();
|
||||
|
||||
var gitVersion = new Version(tag);
|
||||
var appVersion = new Version(Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
if (gitVersion.CompareTo(appVersion) > 0)
|
||||
{
|
||||
settingsForm.BeginInvoke(delegate
|
||||
{
|
||||
settingsForm.SetVersionLabel("Download Update: " + tag, url);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine("Failed to check for updates:"+ ex.Message);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void SetAutoModes(bool wait = false)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using Starlight.AnimeMatrix;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Timers;
|
||||
|
||||
namespace GHelper
|
||||
@@ -23,7 +25,7 @@ namespace GHelper
|
||||
public Keyboard keyb;
|
||||
|
||||
static AnimeMatrixDevice mat;
|
||||
static long lastTip;
|
||||
static long lastRefresh;
|
||||
|
||||
public SettingsForm()
|
||||
{
|
||||
@@ -57,8 +59,6 @@ namespace GHelper
|
||||
|
||||
VisibleChanged += SettingsForm_VisibleChanged;
|
||||
|
||||
trackBattery.Scroll += trackBatteryChange;
|
||||
|
||||
button60Hz.Click += Button60Hz_Click;
|
||||
button120Hz.Click += Button120Hz_Click;
|
||||
buttonScreenAuto.Click += ButtonScreenAuto_Click;
|
||||
@@ -117,6 +117,7 @@ namespace GHelper
|
||||
button120Hz.MouseMove += Button120Hz_MouseHover;
|
||||
button120Hz.MouseLeave += ButtonScreen_MouseLeave;
|
||||
|
||||
trackBattery.ValueChanged += TrackBattery_ValueChanged;
|
||||
Program.trayIcon.MouseMove += TrayIcon_MouseMove;
|
||||
|
||||
//buttonStandard.Image = (Image)(new Bitmap(buttonStandard.Image, new Size(16, 16)));
|
||||
@@ -124,20 +125,71 @@ namespace GHelper
|
||||
aTimer = new System.Timers.Timer(500);
|
||||
aTimer.Elapsed += OnTimedEvent;
|
||||
|
||||
SetVersionLabel("Version: " + Assembly.GetExecutingAssembly().GetName().Version);
|
||||
Thread t = new Thread(() =>
|
||||
{
|
||||
CheckForUpdatesAsync();
|
||||
});
|
||||
t.Start();
|
||||
t.Join();
|
||||
|
||||
}
|
||||
|
||||
private void TrackBattery_ValueChanged(object? sender, EventArgs e)
|
||||
{
|
||||
SetBatteryChargeLimit(trackBattery.Value);
|
||||
}
|
||||
|
||||
|
||||
public async void CheckForUpdatesAsync()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", "C# App");
|
||||
var json = await httpClient.GetStringAsync("https://api.github.com/repos/seerge/g-helper/releases/latest");
|
||||
var config = JsonSerializer.Deserialize<JsonElement>(json);
|
||||
var tag = config.GetProperty("tag_name").ToString().Replace("v", "");
|
||||
var url = config.GetProperty("assets")[0].GetProperty("browser_download_url").ToString();
|
||||
|
||||
Thread.Sleep(5000);
|
||||
|
||||
var gitVersion = new Version(tag);
|
||||
var appVersion = new Version(Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
|
||||
if (gitVersion.CompareTo(appVersion) > 0)
|
||||
{
|
||||
BeginInvoke(delegate
|
||||
{
|
||||
SetVersionLabel("Download Update: " + tag, url);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("Latest version");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Logger.WriteLine("Failed to check for updates:" + ex.Message);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void TrayIcon_MouseMove(object? sender, MouseEventArgs e)
|
||||
{
|
||||
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastTip) < 2000) return;
|
||||
lastTip = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
RefreshSensors();
|
||||
}
|
||||
|
||||
|
||||
private static void OnTimedEvent(Object? source, ElapsedEventArgs? e)
|
||||
{
|
||||
aTimer.Interval = 2000;
|
||||
if (Program.settingsForm.Visible)
|
||||
RefreshSensors();
|
||||
}
|
||||
|
||||
@@ -233,12 +285,12 @@ namespace GHelper
|
||||
}
|
||||
|
||||
|
||||
public void SetVersionLabel(string label, string url = null)
|
||||
void SetVersionLabel(string label, string url = null)
|
||||
{
|
||||
labelVersion.Text = label;
|
||||
if (url is not null)
|
||||
{
|
||||
versionUrl = url;
|
||||
this.versionUrl = url;
|
||||
labelVersion.ForeColor = Color.Red;
|
||||
}
|
||||
}
|
||||
@@ -798,6 +850,9 @@ namespace GHelper
|
||||
private static void RefreshSensors()
|
||||
{
|
||||
|
||||
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastRefresh) < 2000) return;
|
||||
lastRefresh = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
|
||||
string cpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan));
|
||||
string gpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan));
|
||||
string midFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.Mid_Fan));
|
||||
@@ -1084,7 +1139,7 @@ namespace GHelper
|
||||
|
||||
labelGPU.Text = "GPU Mode: Changing ...";
|
||||
|
||||
new Thread(() =>
|
||||
Thread t = new Thread(() =>
|
||||
{
|
||||
Thread.CurrentThread.IsBackground = true;
|
||||
|
||||
@@ -1099,14 +1154,13 @@ namespace GHelper
|
||||
Program.settingsForm.BeginInvoke(delegate
|
||||
{
|
||||
InitGPUMode();
|
||||
HardwareMonitor.RecreateGpuTemperatureProviderWithRetry();
|
||||
HardwareMonitor.RecreateGpuTemperatureProviderWithDelay();
|
||||
Thread.Sleep(500);
|
||||
AutoScreen(SystemInformation.PowerStatus.PowerLineStatus);
|
||||
});
|
||||
})
|
||||
{
|
||||
});
|
||||
|
||||
}.Start();
|
||||
t.Start();
|
||||
|
||||
}
|
||||
|
||||
@@ -1162,7 +1216,6 @@ namespace GHelper
|
||||
if (changed)
|
||||
{
|
||||
Program.config.setConfig("gpu_mode", GPUMode);
|
||||
HardwareMonitor.RecreateGpuTemperatureProviderWithRetry();
|
||||
}
|
||||
|
||||
if (restart)
|
||||
@@ -1254,19 +1307,12 @@ namespace GHelper
|
||||
|
||||
labelBatteryTitle.Text = "Battery Charge Limit: " + limit.ToString() + "%";
|
||||
trackBattery.Value = limit;
|
||||
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit);
|
||||
|
||||
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit);
|
||||
Program.config.setConfig("charge_limit", limit);
|
||||
|
||||
}
|
||||
|
||||
private void trackBatteryChange(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is null) return;
|
||||
TrackBar bar = (TrackBar)sender;
|
||||
SetBatteryChargeLimit(bar.Value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
Reference in New Issue
Block a user