Improve notifications

This commit is contained in:
Daniel
2021-05-05 17:48:38 +02:00
parent 6245bca6d9
commit 55e55f4d43
2 changed files with 23 additions and 18 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/safing/portbase/database"
"github.com/safing/portbase/database/query"
"github.com/safing/portbase/log"
"github.com/safing/portbase/modules"
"github.com/safing/portbase/updater"
"github.com/tevino/abool"
)
@@ -22,20 +23,20 @@ func tryListUpdate(ctx context.Context) error {
err := performUpdate(ctx)
if err != nil {
if !isLoaded() {
warnAboutDisabledFilterLists()
} else {
// Check if the module already has a failure status set. If not, set a
// generic one with the returned error.
failureStatus, _, _ := module.FailureStatus()
if failureStatus < modules.FailureWarning {
module.Warning(
filterlistsUpdateFailed,
"Filter Lists Update Failed",
fmt.Sprintf("The filter lists system failed to process an update. Depending on the previous state, the filtering capabilities are now either impaired or not given. Refer to the error for more details: %s", err.Error()),
)
}
return err
}
// The list update suceeded, resolve any states.
module.Resolve("")
return nil
}
@@ -46,12 +47,6 @@ func performUpdate(ctx context.Context) error {
}
defer updateInProgress.UnSet()
module.Hint(
filterlistsUpdateInProgress,
"Filter Lists Update In Progress",
"The filter list system is processing updates. While this might slightly degrade performance, the filter list system stays functional during this process.",
)
// First, update the list index.
err := updateListIndex()
if err != nil {
@@ -142,6 +137,8 @@ func performUpdate(ctx context.Context) error {
log.Infof("intel/filterlists: successfully migrated cache database to %s", highestVersion.Version())
}
// The list update suceeded, resolve any states.
module.Resolve("")
return nil
}

View File

@@ -67,6 +67,7 @@ var (
const (
updateInProgress = "updates:in-progress"
updateFailed = "updates:failed"
updateSuccess = "updates:success"
)
func init() {
@@ -266,15 +267,22 @@ func checkForUpdates(ctx context.Context) (err error) {
}
defer log.Debugf("updates: finished checking for updates")
module.Hint(
updateInProgress,
"Checking for Updates",
"The Portmaster is currently checking for and downloading any available updates.",
)
defer func() {
if err == nil {
module.Resolve(updateInProgress)
module.Resolve(updateFailed)
notifications.Notify(&notifications.Notification{
EventID: updateSuccess,
Type: notifications.Info,
Title: "Update Check Successful",
Message: "The Portmaster successfully checked for updates and downloaded any available updates. Most updates are applied automatically. You will be notified of important updates that need restarting.",
Expires: time.Now().Add(20 * time.Second).Unix(),
AvailableActions: []*notifications.Action{
{
ID: "ack",
Text: "OK",
},
},
})
} else {
notifications.NotifyWarn(
updateFailed,