Skip to content

Commit 22f4881

Browse files
committed
minimize to tray, auto refresh stats
1 parent 5a17ba2 commit 22f4881

File tree

9 files changed

+178
-43
lines changed

9 files changed

+178
-43
lines changed

AsusFanControl/AsusControl.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ public AsusControl()
1919
AsusWinIO64.ShutdownWinIo();
2020
}
2121

22-
public void SetFanSpeed(byte value, byte fanIndex = 0)
22+
public async void SetFanSpeed(byte value, byte fanIndex = 0)
2323
{
2424
AsusWinIO64.HealthyTable_SetFanIndex(fanIndex);
25+
await Task.Delay(20);
26+
2527
AsusWinIO64.HealthyTable_SetFanPwmDuty(value);
2628
AsusWinIO64.HealthyTable_SetFanTestMode((char)(value > 0 ? 0x01 : 0x00));
29+
await Task.Delay(20);
2730
}
2831

2932
public void SetFanSpeed(int percent, byte fanIndex = 0)

AsusFanControl/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using AsusSystemAnalysis;
32

43
namespace AsusFanControl
54
{

AsusFanControlGUI/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
<setting name="forbidUnsafeSettings" serializeAs="String">
2020
<value>True</value>
2121
</setting>
22+
<setting name="minimizeToTrayOnClose" serializeAs="String">
23+
<value>False</value>
24+
</setting>
25+
<setting name="autoRefreshStats" serializeAs="String">
26+
<value>False</value>
27+
</setting>
2228
</AsusFanControlGUI.Properties.Settings>
2329
</userSettings>
2430
</configuration>

AsusFanControlGUI/AsusFanControlGUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Properties\AssemblyInfo.cs" />
8080
<EmbeddedResource Include="Form1.resx">
8181
<DependentUpon>Form1.cs</DependentUpon>
82+
<SubType>Designer</SubType>
8283
</EmbeddedResource>
8384
<EmbeddedResource Include="Properties\Resources.resx">
8485
<Generator>ResXFileCodeGenerator</Generator>

AsusFanControlGUI/Form1.Designer.cs

Lines changed: 49 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AsusFanControlGUI/Form1.cs

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Data;
5-
using System.Drawing;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
1+
using AsusFanControl;
2+
using System;
93
using System.Windows.Forms;
10-
using AsusFanControl;
11-
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
124

135
namespace AsusFanControlGUI
146
{
157
public partial class Form1 : Form
168
{
179
AsusControl asusControl = new AsusControl();
1810
int fanSpeed = 0;
11+
Timer timer;
12+
NotifyIcon trayIcon;
1913

2014
public Form1()
2115
{
@@ -24,6 +18,8 @@ public Form1()
2418

2519
toolStripMenuItemTurnOffControlOnExit.Checked = Properties.Settings.Default.turnOffControlOnExit;
2620
toolStripMenuItemForbidUnsafeSettings.Checked = Properties.Settings.Default.forbidUnsafeSettings;
21+
toolStripMenuItemMinimizeToTrayOnClose.Checked = Properties.Settings.Default.minimizeToTrayOnClose;
22+
toolStripMenuItemAutoRefreshStats.Checked = Properties.Settings.Default.autoRefreshStats;
2723
trackBarFanSpeed.Value = Properties.Settings.Default.fanSpeed;
2824
}
2925

@@ -33,6 +29,70 @@ private void OnProcessExit(object sender, EventArgs e)
3329
asusControl.SetFanSpeeds(0);
3430
}
3531

32+
private void Form1_Load(object sender, EventArgs e)
33+
{
34+
timerRefreshStats();
35+
}
36+
37+
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
38+
{
39+
if (Properties.Settings.Default.minimizeToTrayOnClose && Visible)
40+
{
41+
if(trayIcon == null)
42+
{
43+
trayIcon = new NotifyIcon()
44+
{
45+
Icon = Icon,
46+
ContextMenu = new ContextMenu(new MenuItem[] {
47+
new MenuItem("Show", (s1, e1) =>
48+
{
49+
trayIcon.Visible = false;
50+
Show();
51+
}),
52+
new MenuItem("Exit", (s1, e1) =>
53+
{
54+
trayIcon.Visible = false;
55+
Close();
56+
}),
57+
}),
58+
};
59+
60+
trayIcon.Click += (s1, e1) =>
61+
{
62+
trayIcon.Visible = false;
63+
Show();
64+
};
65+
}
66+
67+
trayIcon.Visible = true;
68+
e.Cancel = true;
69+
Hide();
70+
}
71+
}
72+
73+
private void timerRefreshStats()
74+
{
75+
if (timer != null)
76+
{
77+
timer.Stop();
78+
timer = null;
79+
}
80+
81+
if (!Properties.Settings.Default.autoRefreshStats)
82+
return;
83+
84+
timer = new Timer();
85+
timer.Interval = 2000;
86+
timer.Tick += new EventHandler(TimerEventProcessor);
87+
timer.Start();
88+
}
89+
90+
private void TimerEventProcessor(object sender, EventArgs e)
91+
{
92+
buttonRefreshRPM_Click(sender, e);
93+
buttonRefreshCPUTemp_Click(sender, e);
94+
}
95+
3696
private void toolStripMenuItemTurnOffControlOnExit_CheckedChanged(object sender, EventArgs e)
3797
{
3898
Properties.Settings.Default.turnOffControlOnExit = toolStripMenuItemTurnOffControlOnExit.Checked;
@@ -45,6 +105,20 @@ private void toolStripMenuItemForbidUnsafeSettings_CheckedChanged(object sender,
45105
Properties.Settings.Default.Save();
46106
}
47107

108+
private void toolStripMenuItemMinimizeToTrayOnClose_Click(object sender, EventArgs e)
109+
{
110+
Properties.Settings.Default.minimizeToTrayOnClose = toolStripMenuItemMinimizeToTrayOnClose.Checked;
111+
Properties.Settings.Default.Save();
112+
}
113+
114+
private void toolStripMenuItemAutoRefreshStats_Click(object sender, EventArgs e)
115+
{
116+
Properties.Settings.Default.autoRefreshStats = toolStripMenuItemAutoRefreshStats.Checked;
117+
Properties.Settings.Default.Save();
118+
119+
timerRefreshStats();
120+
}
121+
48122
private void toolStripMenuItemCheckForUpdates_Click(object sender, EventArgs e)
49123
{
50124
System.Diagnostics.Process.Start("https://github.com/Karmel0x/AsusFanControl/releases");
@@ -98,14 +172,15 @@ private void trackBarFanSpeed_KeyUp(object sender, KeyEventArgs e)
98172
trackBarFanSpeed_MouseCaptureChanged(sender, e);
99173
}
100174

101-
private void button1_Click(object sender, EventArgs e)
175+
private void buttonRefreshRPM_Click(object sender, EventArgs e)
102176
{
103177
labelRPM.Text = string.Join(" ", asusControl.GetFanSpeeds());
104178
}
105179

106-
private void button2_Click(object sender, EventArgs e)
180+
private void buttonRefreshCPUTemp_Click(object sender, EventArgs e)
107181
{
108182
labelCPUTemp.Text = $"{asusControl.Thermal_Read_Cpu_Temperature()}";
109183
}
184+
110185
}
111186
}

AsusFanControlGUI/Program.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
52
using System.Windows.Forms;
63

74
namespace AsusFanControlGUI

AsusFanControlGUI/Properties/Settings.Designer.cs

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)