Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Connected toast, logged in state #183

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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