Skip to content

Commit d635ac9

Browse files
committed
Debug & code cleaning
- Bumped up reconnect interval for debug mode - Applying code cleaning/simplification to WinNUT.vb - Relocating Properties to near the top of the document - Renamed UPSDisconnect to UPSDisconnectedEvent to better match the purposes of the subroutine. Struggling with the "best" way to handle UPS_Object lifecycle and references
1 parent c2a01b4 commit d635ac9

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Public Class UPS_Device
1414
Private Const CosPhi As Double = 0.6
1515
' How many milliseconds to wait before the Reconnect routine tries again.
1616
#If DEBUG Then
17-
Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 3000
17+
Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 5000
1818
#Else
1919
Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 30000
2020
#End If

WinNUT_V2/WinNUT_GUI/WinNUT.vb

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ Imports WinNUT_Client_Common
1212
Public Class WinNUT
1313
#Region "Properties"
1414

15+
Public Property UpdateMethod() As String
16+
Get
17+
If mUpdate Then
18+
mUpdate = False
19+
Return True
20+
Else
21+
Return False
22+
End If
23+
End Get
24+
Set(Value As String)
25+
mUpdate = Value
26+
End Set
27+
End Property
28+
29+
Public WriteOnly Property HasCrashed() As Boolean
30+
Set(Value As Boolean)
31+
WinNUT_Crashed = Value
32+
End Set
33+
End Property
34+
1535
#End Region
1636
Private WithEvents LogFile As Logger = WinNUT_Globals.LogFile
1737

@@ -29,7 +49,7 @@ Public Class WinNUT
2949

3050
'Variable used with Toast Functionnality
3151
Public WithEvents FrmBuild As Update_Gui
32-
Public ToastPopup As New WinNUT_Client_Common.ToastPopup
52+
Public ToastPopup As New ToastPopup
3353
Private WindowsVersion As Version = Version.Parse(My.Computer.Info.OSVersion)
3454
Private MinOsVersionToast As Version = Version.Parse("10.0.18362.0")
3555
Private AllowToast As Boolean = False
@@ -65,32 +85,14 @@ Public Class WinNUT
6585
Private Event On_Battery()
6686
Private Event On_Line()
6787
' Private Event Data_Updated()
68-
Private Event UpdateNotifyIconStr(ByVal Reason As String, ByVal Message As String)
69-
Private Event UpdateBatteryState(ByVal Reason As String)
88+
Private Event UpdateNotifyIconStr(Reason As String, Message As String)
89+
Private Event UpdateBatteryState(Reason As String)
90+
' UPS object operation
7091
Private Event RequestConnect()
92+
' Private Event RequestDisconnect()
7193

7294
'Handle sleep/hibernate mode from windows API
73-
Declare Function SetSuspendState Lib "PowrProf" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer
74-
75-
Public Property UpdateMethod() As String
76-
Get
77-
If mUpdate Then
78-
mUpdate = False
79-
Return True
80-
Else
81-
Return False
82-
End If
83-
End Get
84-
Set(ByVal Value As String)
85-
mUpdate = Value
86-
End Set
87-
End Property
88-
89-
Public WriteOnly Property HasCrashed() As Boolean
90-
Set(ByVal Value As Boolean)
91-
WinNUT_Crashed = Value
92-
End Set
93-
End Property
95+
Declare Function SetSuspendState Lib "PowrProf" (Hibernate As Integer, ForceCritical As Integer, DisableWakeEvent As Integer) As Integer
9496

9597
Private Sub WinNUT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
9698
' Make sure we have an app directory to write to.
@@ -283,7 +285,7 @@ Public Class WinNUT
283285
' RaiseEvent RequestConnect()
284286
End Sub
285287

286-
Private Sub SystemEvents_PowerModeChanged(ByVal sender As Object, ByVal e As Microsoft.Win32.PowerModeChangedEventArgs)
288+
Private Sub SystemEvents_PowerModeChanged(sender As Object, e As Microsoft.Win32.PowerModeChangedEventArgs)
287289
Select Case e.Mode
288290
Case Microsoft.Win32.PowerModes.Resume
289291
LogFile.LogTracing("Restarting WinNUT after waking up from Windows", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
@@ -354,7 +356,7 @@ Public Class WinNUT
354356
''' <summary>
355357
''' Prepare application for and handle disconnecting from the UPS.
356358
''' </summary>
357-
Private Sub UPSDisconnect() Handles UPS_Device.Disconnected
359+
Private Sub UPSDisconnectedEvent() Handles UPS_Device.Disconnected
358360
' LogFile.LogTracing("Running Client disconnect subroutine.", LogLvl.LOG_DEBUG, Me)
359361

360362
' Update_Data.Stop()
@@ -509,7 +511,7 @@ Public Class WinNUT
509511

510512

511513

512-
Private Sub Event_UpdateNotifyIconStr(ByVal Optional Reason As String = Nothing, ByVal Optional Message As String = Nothing) Handles Me.UpdateNotifyIconStr
514+
Private Sub Event_UpdateNotifyIconStr(Optional Reason As String = Nothing, Optional Message As String = Nothing) Handles Me.UpdateNotifyIconStr
513515
Dim ShowVersion As String = ShortProgramVersion
514516
Dim NotifyStr As String = ProgramName & " - " & ShowVersion & vbNewLine
515517
Dim FormText As String = ProgramName
@@ -568,7 +570,7 @@ Public Class WinNUT
568570
LogFile.LogTracing("NotifyIcon Text => " & vbNewLine & NotifyStr, LogLvl.LOG_DEBUG, Me)
569571
End Sub
570572

571-
Private Sub Event_UpdateBatteryState(ByVal Optional Reason As String = Nothing) Handles Me.UpdateBatteryState
573+
Private Sub Event_UpdateBatteryState(Optional Reason As String = Nothing) Handles Me.UpdateBatteryState
572574
Static Dim Old_Battery_Value As Integer = UPS_BattCh
573575
Dim Status As String = "Unknown"
574576
Select Case Reason
@@ -621,7 +623,7 @@ Public Class WinNUT
621623
Private Sub UPS_Lostconnect() Handles UPS_Device.Lost_Connect
622624
LogFile.LogTracing("Notify user of lost connection", LogLvl.LOG_ERROR, Me,
623625
String.Format(StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), UPS_Device.Nut_Config.Host, UPS_Device.Nut_Config.Port))
624-
UPSDisconnect()
626+
UPSDisconnectedEvent()
625627
'Dim Host = UPS_Device.Nut_Config.Host
626628
'Dim Port = UPS_Device.Nut_Config.Port
627629
'Update_Data.Stop()
@@ -1013,7 +1015,7 @@ Public Class WinNUT
10131015
End If
10141016
End Sub
10151017

1016-
Private Function GetIcon(ByVal IconIdx As Integer) As Icon
1018+
Private Function GetIcon(IconIdx As Integer) As Icon
10171019
Select Case IconIdx
10181020
Case 1025
10191021
Return My.Resources._1025

0 commit comments

Comments
 (0)