Update and improve notifications according to new system

This commit is contained in:
Daniel
2021-05-05 00:27:34 +02:00
parent fa58de2e1b
commit 2e73d4fbe6
8 changed files with 96 additions and 49 deletions

View File

@@ -3,12 +3,15 @@ package updates
import (
"context"
"github.com/safing/portbase/notifications"
"github.com/safing/portbase/config"
"github.com/safing/portbase/log"
)
const (
cfgDevModeKey = "core/devMode"
cfgDevModeKey = "core/devMode"
updatesDisabledNotificationID = "updates:disabled"
)
var (
@@ -85,7 +88,6 @@ func initConfig() {
func updateRegistryConfig(_ context.Context, _ interface{}) error {
changed := false
forceUpdate := false
if releaseChannel() != previousReleaseChannel {
registry.SetBeta(releaseChannel() == releaseChannelBeta)
@@ -102,20 +104,33 @@ func updateRegistryConfig(_ context.Context, _ interface{}) error {
if enableUpdates() != updatesCurrentlyEnabled {
updatesCurrentlyEnabled = enableUpdates()
changed = true
forceUpdate = updatesCurrentlyEnabled
}
if changed {
registry.SelectVersions()
module.TriggerEvent(VersionUpdateEvent, nil)
if forceUpdate {
module.Resolve(updateFailed)
_ = TriggerUpdate()
log.Infof("updates: automatic updates enabled again.")
} else if !updatesCurrentlyEnabled {
module.Warning(updateFailed, "Automatic updates are disabled! This also affects security updates and threat intelligence.")
log.Warningf("updates: automatic updates are now disabled.")
if updatesCurrentlyEnabled {
module.Resolve("")
if err := TriggerUpdate(); err != nil {
log.Warningf("updates: failed to trigger update: %s", err)
}
log.Infof("updates: automatic updates are now enabled")
} else {
notifications.NotifyWarn(
updatesDisabledNotificationID,
"Automatic Updates Disabled",
"The automatic update system is disabled through configuration. Please note that this is potentially dangerous, as this also affects security updates as well as the filter lists and threat intelligence feeds.",
notifications.Action{
ID: "change",
Text: "Change",
Type: notifications.ActionTypeOpenSetting,
Payload: &notifications.ActionTypeOpenSettingPayload{
Key: enableUpdatesKey,
},
},
).AttachToModule(module)
log.Warningf("updates: automatic updates are now disabled")
}
}

View File

@@ -278,13 +278,30 @@ func checkForUpdates(ctx context.Context) (err error) {
}
defer log.Debugf("updates: finished checking for updates")
module.Hint(updateInProgress, updateInProcessDescr)
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)
} else {
module.Warning(updateFailed, "Failed to update: "+err.Error())
notifications.NotifyWarn(
updateFailed,
"Update Check Failed",
"The Portmaster failed to check for updates. This might be a temporary issue of your device, your network or the update servers. The Portmaster will automatically try again later.",
notifications.Action{
ID: "retry",
Text: "Try Again",
Type: notifications.ActionTypeWebhook,
Payload: &notifications.ActionTypeWebhookPayload{
URL: apiPathCheckForUpdates,
ResultAction: "display",
},
},
).AttachToModule(module)
}
}()

View File

@@ -109,10 +109,10 @@ func upgradeCoreNotify() error {
),
Category: "Core",
Message: fmt.Sprintf(
`:tada: Update to **Portmaster v%s** is available!
Please restart the Portmaster to apply the update.`,
`A new Portmaster version is available! Restart the Portmaster to upgrade to %s.`,
pmCoreUpdate.Version(),
),
ShowOnSystem: true,
AvailableActions: []*notifications.Action{
{
ID: "restart",
@@ -257,13 +257,10 @@ func warnOnIncorrectParentPath() {
root := filepath.Dir(registry.StorageDir().Path)
if !strings.HasPrefix(absPath, root) {
log.Warningf("detected unexpected path %s for portmaster-start", absPath)
notifications.Notify(&notifications.Notification{
EventID: "updates:unsupported-parent",
Type: notifications.Warning,
Title: "Unsupported Launcher",
Category: "Core",
Message: fmt.Sprintf(
notifications.NotifyWarn(
"updates:unsupported-parent",
"Unsupported Launcher",
fmt.Sprintf(
"The portmaster has been launched by an unexpected %s binary at %s. Please configure your system to use the binary at %s as this version will be kept up to date automatically.",
expectedFileName,
absPath,