Improve captive portal notification handling

This commit is contained in:
Daniel
2021-10-14 14:18:52 +02:00
parent 7e21e7c7d7
commit 17da727ac0

View File

@@ -191,12 +191,7 @@ func updateOnlineStatus(status OnlineStatus, portalURL *url.URL, comment string)
} }
// captive portal // captive portal
// delete if offline, update only if there is a new value setCaptivePortal(portalURL)
if status == StatusOffline || portalURL != nil {
setCaptivePortal(portalURL)
} else if status == StatusOnline {
cleanUpPortalNotification()
}
// trigger event // trigger event
if changed { if changed {
@@ -222,7 +217,10 @@ func setCaptivePortal(portalURL *url.URL) {
// delete // delete
if portalURL == nil { if portalURL == nil {
captivePortal = &CaptivePortal{} captivePortal = &CaptivePortal{}
cleanUpPortalNotification() if captivePortalNotification != nil {
captivePortalNotification.Delete()
captivePortalNotification = nil
}
return return
} }
@@ -244,7 +242,6 @@ func setCaptivePortal(portalURL *url.URL) {
} }
// notify // notify
cleanUpPortalNotification()
captivePortalNotification = notifications.Notify(&notifications.Notification{ captivePortalNotification = notifications.Notify(&notifications.Notification{
EventID: "netenv:captive-portal", EventID: "netenv:captive-portal",
Type: notifications.Info, 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. // GetCaptivePortal returns the current captive portal. The returned struct must not be edited.
func GetCaptivePortal() *CaptivePortal { func GetCaptivePortal() *CaptivePortal {
captivePortalLock.Lock() captivePortalLock.Lock()