Skip to content

Commit 7959f5e

Browse files
authored
Merge pull request #183 from nutdotnet/fix-toasts
Fix Connected toast, logged in state
2 parents d5f124d + eb6bfc6 commit 7959f5e

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

WinNUT_V2/WinNUT-Client/WinNUT.vb

+18-16
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ Public Class WinNUT
402402
LogFile.LogTracing("Connection to Nut Host Established", LogLvl.LOG_NOTICE, Me,
403403
String.Format(StrLog.Item(AppResxStr.STR_LOG_CONNECTED),
404404
upsConf.Host, upsConf.Port))
405-
406-
If Not String.IsNullOrEmpty(upsConf.Login) Then
407-
UPS_Device.Login()
408-
End If
409405
End Sub
410406

411407
Private Sub ConnectionError(sender As UPS_Device, ex As Exception) Handles UPS_Device.ConnectionError
@@ -618,18 +614,6 @@ Public Class WinNUT
618614
HasFocus = False
619615
End Sub
620616

621-
Public Shared Sub Event_ChangeStatus() Handles Me.On_Battery, Me.On_Line,
622-
UPS_Device.Lost_Connect, UPS_Device.Connected, UPS_Device.Disconnected
623-
624-
WinNUT.NotifyIcon.BalloonTipText = WinNUT.NotifyIcon.Text
625-
If WinNUT.AllowToast And WinNUT.NotifyIcon.BalloonTipText <> "" Then
626-
Dim Toastparts As String() = WinNUT.NotifyIcon.BalloonTipText.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
627-
WinNUT.ToastPopup.SendToast(Toastparts)
628-
ElseIf WinNUT.NotifyIcon.Visible = True And WinNUT.NotifyIcon.BalloonTipText <> "" Then
629-
WinNUT.NotifyIcon.ShowBalloonTip(10000)
630-
End If
631-
End Sub
632-
633617
Private Sub Update_UPS_Data() Handles UPS_Device.DataUpdated
634618
LogFile.LogTracing("Updating UPS data for Form.", LogLvl.LOG_DEBUG, Me)
635619

@@ -875,6 +859,24 @@ Public Class WinNUT
875859
End If
876860
End Sub
877861

862+
''' <summary>
863+
''' Handle Toast (Windows 10+) and/or NotifyIcon pop-ups.
864+
''' </summary>
865+
Private Sub ToastNotifyIcon() Handles Me.On_Battery, Me.On_Line, UPS_Device.Lost_Connect,
866+
UPS_Device.Connected, UPS_Device.Disconnected
867+
868+
LogFile.LogTracing("ToastNotifyIcon running.", LogLvl.LOG_DEBUG, Me)
869+
NotifyIcon.BalloonTipText = NotifyIcon.Text
870+
If AllowToast And NotifyIcon.BalloonTipText <> "" Then
871+
Dim Toastparts As String() = NotifyIcon.BalloonTipText.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
872+
LogFile.LogTracing("Sending Toast popup with text: " & NotifyIcon.BalloonTipText, LogLvl.LOG_DEBUG, Me)
873+
ToastPopup.SendToast(Toastparts)
874+
ElseIf NotifyIcon.Visible = True And NotifyIcon.BalloonTipText <> "" Then
875+
LogFile.LogTracing("Sending NotifyIcon ballowtip: " & NotifyIcon.BalloonTipText, LogLvl.LOG_DEBUG, Me)
876+
NotifyIcon.ShowBalloonTip(10000)
877+
End If
878+
End Sub
879+
878880
Private Function GetIcon(IconIdx As Integer) As Icon
879881
Select Case IconIdx
880882
Case 1025

WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Public Class Nut_Socket
128128
Query_Data("LOGOUT")
129129
End If
130130

131+
_isLoggedIn = False
132+
131133
If WriterStream IsNot Nothing Then
132134
WriterStream.Dispose()
133135
End If

WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ Public Class UPS_Device
144144
Update_Data.Start()
145145
RaiseEvent Connected(Me)
146146

147+
If Not String.IsNullOrEmpty(Nut_Config.Login) Then
148+
Login()
149+
End If
150+
147151
Catch ex As NutException
148152
' This is how we determine if we have a valid UPS name entered, among other errors.
149153
RaiseEvent EncounteredNUTException(Me, ex)

0 commit comments

Comments
 (0)