Skip to content

Commit

Permalink
Merge pull request #183 from nutdotnet/fix-toasts
Browse files Browse the repository at this point in the history
Fix Connected toast, logged in state
  • Loading branch information
gbakeman authored Sep 27, 2024
2 parents d5f124d + eb6bfc6 commit 7959f5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
34 changes: 18 additions & 16 deletions WinNUT_V2/WinNUT-Client/WinNUT.vb
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,6 @@ Public Class WinNUT
LogFile.LogTracing("Connection to Nut Host Established", LogLvl.LOG_NOTICE, Me,
String.Format(StrLog.Item(AppResxStr.STR_LOG_CONNECTED),
upsConf.Host, upsConf.Port))

If Not String.IsNullOrEmpty(upsConf.Login) Then
UPS_Device.Login()
End If
End Sub

Private Sub ConnectionError(sender As UPS_Device, ex As Exception) Handles UPS_Device.ConnectionError
Expand Down Expand Up @@ -618,18 +614,6 @@ Public Class WinNUT
HasFocus = False
End Sub

Public Shared Sub Event_ChangeStatus() Handles Me.On_Battery, Me.On_Line,
UPS_Device.Lost_Connect, UPS_Device.Connected, UPS_Device.Disconnected

WinNUT.NotifyIcon.BalloonTipText = WinNUT.NotifyIcon.Text
If WinNUT.AllowToast And WinNUT.NotifyIcon.BalloonTipText <> "" Then
Dim Toastparts As String() = WinNUT.NotifyIcon.BalloonTipText.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
WinNUT.ToastPopup.SendToast(Toastparts)
ElseIf WinNUT.NotifyIcon.Visible = True And WinNUT.NotifyIcon.BalloonTipText <> "" Then
WinNUT.NotifyIcon.ShowBalloonTip(10000)
End If
End Sub

Private Sub Update_UPS_Data() Handles UPS_Device.DataUpdated
LogFile.LogTracing("Updating UPS data for Form.", LogLvl.LOG_DEBUG, Me)

Expand Down Expand Up @@ -875,6 +859,24 @@ Public Class WinNUT
End If
End Sub

''' <summary>
''' Handle Toast (Windows 10+) and/or NotifyIcon pop-ups.
''' </summary>
Private Sub ToastNotifyIcon() Handles Me.On_Battery, Me.On_Line, UPS_Device.Lost_Connect,
UPS_Device.Connected, UPS_Device.Disconnected

LogFile.LogTracing("ToastNotifyIcon running.", LogLvl.LOG_DEBUG, Me)
NotifyIcon.BalloonTipText = NotifyIcon.Text
If AllowToast And NotifyIcon.BalloonTipText <> "" Then
Dim Toastparts As String() = NotifyIcon.BalloonTipText.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
LogFile.LogTracing("Sending Toast popup with text: " & NotifyIcon.BalloonTipText, LogLvl.LOG_DEBUG, Me)
ToastPopup.SendToast(Toastparts)
ElseIf NotifyIcon.Visible = True And NotifyIcon.BalloonTipText <> "" Then
LogFile.LogTracing("Sending NotifyIcon ballowtip: " & NotifyIcon.BalloonTipText, LogLvl.LOG_DEBUG, Me)
NotifyIcon.ShowBalloonTip(10000)
End If
End Sub

Private Function GetIcon(IconIdx As Integer) As Icon
Select Case IconIdx
Case 1025
Expand Down
2 changes: 2 additions & 0 deletions WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Public Class Nut_Socket
Query_Data("LOGOUT")
End If

_isLoggedIn = False

If WriterStream IsNot Nothing Then
WriterStream.Dispose()
End If
Expand Down
4 changes: 4 additions & 0 deletions WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ Public Class UPS_Device
Update_Data.Start()
RaiseEvent Connected(Me)

If Not String.IsNullOrEmpty(Nut_Config.Login) Then
Login()
End If

Catch ex As NutException
' This is how we determine if we have a valid UPS name entered, among other errors.
RaiseEvent EncounteredNUTException(Me, ex)
Expand Down

0 comments on commit 7959f5e

Please sign in to comment.