From 17da727ac0bc5abb8080ef9fda992ff1ade91f3c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 14 Oct 2021 14:18:52 +0200 Subject: [PATCH] Improve captive portal notification handling --- netenv/online-status.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/netenv/online-status.go b/netenv/online-status.go index c29ba513..099e438e 100644 --- a/netenv/online-status.go +++ b/netenv/online-status.go @@ -191,12 +191,7 @@ func updateOnlineStatus(status OnlineStatus, portalURL *url.URL, comment string) } // captive portal - // delete if offline, update only if there is a new value - if status == StatusOffline || portalURL != nil { - setCaptivePortal(portalURL) - } else if status == StatusOnline { - cleanUpPortalNotification() - } + setCaptivePortal(portalURL) // trigger event if changed { @@ -222,7 +217,10 @@ func setCaptivePortal(portalURL *url.URL) { // delete if portalURL == nil { captivePortal = &CaptivePortal{} - cleanUpPortalNotification() + if captivePortalNotification != nil { + captivePortalNotification.Delete() + captivePortalNotification = nil + } return } @@ -244,7 +242,6 @@ func setCaptivePortal(portalURL *url.URL) { } // notify - cleanUpPortalNotification() captivePortalNotification = notifications.Notify(¬ifications.Notification{ EventID: "netenv:captive-portal", Type: notifications.Info, @@ -266,13 +263,6 @@ func setCaptivePortal(portalURL *url.URL) { }) } -func cleanUpPortalNotification() { - if captivePortalNotification != nil { - captivePortalNotification.Delete() - captivePortalNotification = nil - } -} - // GetCaptivePortal returns the current captive portal. The returned struct must not be edited. func GetCaptivePortal() *CaptivePortal { captivePortalLock.Lock()