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 ;
93using System . Windows . Forms ;
10- using AsusFanControl ;
11- using static System . Windows . Forms . VisualStyles . VisualStyleElement ;
124
135namespace 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}
0 commit comments