From 82cdfe6a2ccfeee8f09d469b7f9dd91fa3fa048a Mon Sep 17 00:00:00 2001 From: g-cranston <95360513+g-cranston@users.noreply.github.com> Date: Tue, 15 Feb 2022 23:54:39 +0000 Subject: [PATCH 1/3] Update WinNUT.vb --- WinNUT_V2/WinNUT_GUI/WinNUT.vb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WinNUT_V2/WinNUT_GUI/WinNUT.vb b/WinNUT_V2/WinNUT_GUI/WinNUT.vb index a1b5264..00c5380 100644 --- a/WinNUT_V2/WinNUT_GUI/WinNUT.vb +++ b/WinNUT_V2/WinNUT_GUI/WinNUT.vb @@ -100,7 +100,7 @@ Public Class WinNUT Private Event On_Line() Private Event UpdateNotifyIconStr(ByVal Reason As String, ByVal Message As String) Private Event UpdateBatteryState(ByVal Reason As String) - Declare Function SetSystemPowerState Lib "kernel32" (ByVal fSuspend As Integer, ByVal fForce As Integer) As Integer + Declare Function SetSuspendState Lib "PowrProf" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer Public Property UpdateMethod() As String Get @@ -980,9 +980,9 @@ Public Class WinNUT Case 0 Process.Start("C:\WINDOWS\system32\Shutdown.exe", "-f -s -t 0") Case 1 - SetSystemPowerState(True, 0) + SetSuspendState(False, False, True) 'Suspend Case 2 - SetSystemPowerState(False, 0) + SetSuspendState(True, False, True) 'Hibernate End Select End Sub From 0db12195162755f657e4f453604e78b1f2daa6ba Mon Sep 17 00:00:00 2001 From: g-cranston <95360513+g-cranston@users.noreply.github.com> Date: Wed, 16 Feb 2022 00:02:03 +0000 Subject: [PATCH 2/3] Update Shutdown_Gui.vb --- WinNUT_V2/WinNUT_GUI/Shutdown_Gui.vb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WinNUT_V2/WinNUT_GUI/Shutdown_Gui.vb b/WinNUT_V2/WinNUT_GUI/Shutdown_Gui.vb index 192c33f..8a5bf6c 100644 --- a/WinNUT_V2/WinNUT_GUI/Shutdown_Gui.vb +++ b/WinNUT_V2/WinNUT_GUI/Shutdown_Gui.vb @@ -97,6 +97,12 @@ Public Class Shutdown_Gui System.Threading.Thread.Sleep(1000) WinNUT.Shutdown_Action() Run_Timer.Enabled = False + Me.Shutdown_Timer.Stop() + Me.Shutdown_Timer.Enabled = False + Me.Grace_Timer.Stop() + Me.Grace_Timer.Enabled = False + Me.Hide() + Me.Close() End Sub Private Sub Run_Timer_Tick(sender As Object, e As EventArgs) Handles Run_Timer.Tick @@ -137,4 +143,4 @@ Public Class Shutdown_Gui e.Cancel = True End If End Sub -End Class \ No newline at end of file +End Class From 773b2b9bbe8fc8ed8e51f8f80fcdab70ee87271a Mon Sep 17 00:00:00 2001 From: gbakeman Date: Mon, 25 Jul 2022 14:47:33 -0700 Subject: [PATCH 3/3] Merging g-cranston's patch and the Dev-2.1 changes - Un-sharing some Subs, reducing self-referential verbosity --- WinNUT_V2/WinNUT_GUI/WinNUT.vb | 76 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/WinNUT_V2/WinNUT_GUI/WinNUT.vb b/WinNUT_V2/WinNUT_GUI/WinNUT.vb index 4230566..ed61c4f 100644 --- a/WinNUT_V2/WinNUT_GUI/WinNUT.vb +++ b/WinNUT_V2/WinNUT_GUI/WinNUT.vb @@ -428,27 +428,27 @@ Public Class WinNUT End If End Sub - Private Shared Sub NewRetry_NotifyIcon() Handles UPS_Device.New_Retry - Dim Message As String = String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_RETRY), WinNUT.UPS_Device.Retry, WinNUT.UPS_Device.MaxRetry) + Private Sub NewRetry_NotifyIcon() Handles UPS_Device.New_Retry + Dim Message As String = String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_RETRY), UPS_Device.Retry, UPS_Device.MaxRetry) RaiseEvent UpdateNotifyIconStr("Retry", Message) - WinNUT.UpdateIcon_NotifyIcon() - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, WinNUT) + UpdateIcon_NotifyIcon() + LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) End Sub - Private Shared Sub Reconnect_NotifyIcon() Handles UPS_Device.Connected - WinNUT.Menu_UPS_Var.Enabled = True - WinNUT.UpdateIcon_NotifyIcon() - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, WinNUT) + Private Sub Reconnect_NotifyIcon() Handles UPS_Device.Connected + Menu_UPS_Var.Enabled = True + UpdateIcon_NotifyIcon() + LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) RaiseEvent UpdateNotifyIconStr("Connected", Nothing) End Sub - Private Shared Sub Deconnected_NotifyIcon() Handles UPS_Device.Deconnected - WinNUT.ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, WinNUT) - WinNUT.UpdateIcon_NotifyIcon() + Private Sub Deconnected_NotifyIcon() Handles UPS_Device.Deconnected + ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE + LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) + UpdateIcon_NotifyIcon() RaiseEvent UpdateNotifyIconStr("Deconnected", Nothing) RaiseEvent UpdateBatteryState("Deconnected") - WinNUT.Update_Data.Stop() + Update_Data.Stop() End Sub Private Sub Event_UpdateNotifyIconStr(ByVal Optional Reason As String = Nothing, ByVal Optional Message As String = Nothing) Handles Me.UpdateNotifyIconStr @@ -537,13 +537,13 @@ Public Class WinNUT LogFile.LogTracing("Battery Status => " & Status, LogLvl.LOG_DEBUG, WinNUT) End Sub - Public Shared Sub Event_Unknown_UPS() Handles UPS_Device.Unknown_UPS, UPS_Device.Unknown_UPS - WinNUT.ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, WinNUT) - WinNUT.UpdateIcon_NotifyIcon() + Public Sub Event_Unknown_UPS() Handles UPS_Device.Unknown_UPS, UPS_Device.Unknown_UPS + ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE + LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) + UpdateIcon_NotifyIcon() RaiseEvent UpdateNotifyIconStr("Unknown UPS", Nothing) - LogFile.LogTracing("Cannot Connect : Unknow UPS Name", LogLvl.LOG_DEBUG, WinNUT, WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_UNKNOWN_UPS)) - WinNUT.Menu_UPS_Var.Enabled = False + LogFile.LogTracing("Cannot Connect : Unknow UPS Name", LogLvl.LOG_DEBUG, Me, WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_UNKNOWN_UPS)) + Menu_UPS_Var.Enabled = False End Sub Private Sub Menu_About_Click(sender As Object, e As EventArgs) Handles Menu_About.Click @@ -560,27 +560,25 @@ Public Class WinNUT HasFocus = False End Sub - Private Shared Sub UPS_Lostconnect() Handles UPS_Device.Lost_Connect - With WinNUT - Dim Host = .Nut_Config.Host - Dim Port = .Nut_Config.Port - .Update_Data.Stop() - LogFile.LogTracing("Nut Server Lost Connection", LogLvl.LOG_ERROR, WinNUT, String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), Host, Port)) - LogFile.LogTracing("Fix All data to null/empty String", LogLvl.LOG_DEBUG, WinNUT) - LogFile.LogTracing("Fix All Dial Data to Min Value/0", LogLvl.LOG_DEBUG, WinNUT) - - .ReInitDisplayValues() - If .AutoReconnect And .UPS_Retry <= .UPS_MaxRetry Then - .ActualAppIconIdx = AppIconIdx.IDX_ICO_RETRY - Else - .ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE - End If + Private Sub UPS_Lostconnect() Handles UPS_Device.Lost_Connect + Dim Host = Nut_Config.Host + Dim Port = Nut_Config.Port + Update_Data.Stop() + LogFile.LogTracing("Nut Server Lost Connection", LogLvl.LOG_ERROR, Me, String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), Host, Port)) + LogFile.LogTracing("Fix All data to null/empty String", LogLvl.LOG_DEBUG, Me) + LogFile.LogTracing("Fix All Dial Data to Min Value/0", LogLvl.LOG_DEBUG, Me) - .UpdateIcon_NotifyIcon() - RaiseEvent UpdateNotifyIconStr("Lost Connect", Nothing) - RaiseEvent UpdateBatteryState("Lost Connect") - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, WinNUT) - End With + ReInitDisplayValues() + If AutoReconnect And UPS_Retry <= UPS_MaxRetry Then + ActualAppIconIdx = AppIconIdx.IDX_ICO_RETRY + Else + ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE + End If + + UpdateIcon_NotifyIcon() + RaiseEvent UpdateNotifyIconStr("Lost Connect", Nothing) + RaiseEvent UpdateBatteryState("Lost Connect") + LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) End Sub Public Shared Sub Event_ChangeStatus() Handles Me.On_Battery, Me.On_Line,