mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +00:00
Improve updater notifications
This commit is contained in:
parent
1bd3b8863f
commit
9f148f9ea3
2 changed files with 75 additions and 58 deletions
|
@ -21,6 +21,7 @@ const (
|
||||||
updateTaskRepeatDuration = 1 * time.Hour
|
updateTaskRepeatDuration = 1 * time.Hour
|
||||||
noNewUpdateNotificationID = "updates:no-new-update"
|
noNewUpdateNotificationID = "updates:no-new-update"
|
||||||
updateAvailableNotificationID = "updates:update-available"
|
updateAvailableNotificationID = "updates:update-available"
|
||||||
|
restartRequiredNotificationID = "updates:restart-required"
|
||||||
updateFailedNotificationID = "updates:update-failed"
|
updateFailedNotificationID = "updates:update-failed"
|
||||||
corruptInstallationNotificationID = "updates:corrupt-installation"
|
corruptInstallationNotificationID = "updates:corrupt-installation"
|
||||||
|
|
||||||
|
@ -216,11 +217,19 @@ func (u *Updater) updateAndUpgrade(w *mgr.WorkerCtx, indexURLs []string, ignoreV
|
||||||
if err := index.ShouldUpgradeTo(downloader.index); err != nil {
|
if err := index.ShouldUpgradeTo(downloader.index); err != nil {
|
||||||
log.Infof("updates/%s: no new or eligible update: %s", u.cfg.Name, err)
|
log.Infof("updates/%s: no new or eligible update: %s", u.cfg.Name, err)
|
||||||
if u.cfg.Notify && u.instance.Notifications() != nil {
|
if u.cfg.Notify && u.instance.Notifications() != nil {
|
||||||
u.instance.Notifications().NotifyInfo(
|
u.instance.Notifications().Notify(¬ifications.Notification{
|
||||||
noNewUpdateNotificationID,
|
EventID: noNewUpdateNotificationID,
|
||||||
"No Updates Available",
|
Type: notifications.Info,
|
||||||
"Portmaster v"+u.index.Version+" is the newest version.",
|
Title: "Portmaster Is Up-To-Date",
|
||||||
)
|
Message: "Portmaster v" + index.Version + " is the newest version.",
|
||||||
|
Expires: time.Now().Add(1 * time.Minute).Unix(),
|
||||||
|
AvailableActions: []*notifications.Action{
|
||||||
|
{
|
||||||
|
ID: "ack",
|
||||||
|
Text: "OK",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return ErrNoUpdateAvailable
|
return ErrNoUpdateAvailable
|
||||||
}
|
}
|
||||||
|
@ -229,20 +238,27 @@ func (u *Updater) updateAndUpgrade(w *mgr.WorkerCtx, indexURLs []string, ignoreV
|
||||||
// Check if automatic downloads are enabled.
|
// Check if automatic downloads are enabled.
|
||||||
if !u.cfg.AutoDownload && !forceApply {
|
if !u.cfg.AutoDownload && !forceApply {
|
||||||
if u.cfg.Notify && u.instance.Notifications() != nil {
|
if u.cfg.Notify && u.instance.Notifications() != nil {
|
||||||
u.instance.Notifications().NotifyInfo(
|
u.instance.Notifications().Notify(¬ifications.Notification{
|
||||||
updateAvailableNotificationID,
|
EventID: updateAvailableNotificationID,
|
||||||
"New Update",
|
Type: notifications.Info,
|
||||||
"Portmaster v"+downloader.index.Version+" is available. Click Upgrade to download and upgrade now.",
|
Title: "New Update Available",
|
||||||
notifications.Action{
|
Message: "Portmaster v" + downloader.index.Version + " is available. Click Upgrade to download and upgrade now.",
|
||||||
ID: "upgrade",
|
AvailableActions: []*notifications.Action{
|
||||||
Text: "Upgrade Now",
|
{
|
||||||
Type: notifications.ActionTypeWebhook,
|
ID: "ack",
|
||||||
Payload: notifications.ActionTypeWebhookPayload{
|
Text: "OK",
|
||||||
Method: "POST",
|
},
|
||||||
URL: "updates/apply",
|
{
|
||||||
|
ID: "upgrade",
|
||||||
|
Text: "Upgrade Now",
|
||||||
|
Type: notifications.ActionTypeWebhook,
|
||||||
|
Payload: notifications.ActionTypeWebhookPayload{
|
||||||
|
Method: "POST",
|
||||||
|
URL: "updates/apply",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%w: apply updates to download and upgrade", ErrActionRequired)
|
return fmt.Errorf("%w: apply updates to download and upgrade", ErrActionRequired)
|
||||||
}
|
}
|
||||||
|
@ -267,20 +283,27 @@ func (u *Updater) updateAndUpgrade(w *mgr.WorkerCtx, indexURLs []string, ignoreV
|
||||||
// Notify the user that an upgrade is available.
|
// Notify the user that an upgrade is available.
|
||||||
if !u.cfg.AutoApply && !forceApply {
|
if !u.cfg.AutoApply && !forceApply {
|
||||||
if u.cfg.Notify && u.instance.Notifications() != nil {
|
if u.cfg.Notify && u.instance.Notifications() != nil {
|
||||||
u.instance.Notifications().NotifyInfo(
|
u.instance.Notifications().Notify(¬ifications.Notification{
|
||||||
updateAvailableNotificationID,
|
EventID: updateAvailableNotificationID,
|
||||||
"New Update",
|
Type: notifications.Info,
|
||||||
"Portmaster v"+downloader.index.Version+" is available. Click Upgrade to upgrade now.",
|
Title: "New Update Ready",
|
||||||
notifications.Action{
|
Message: "Portmaster v" + downloader.index.Version + " is available. Click Upgrade to upgrade now.",
|
||||||
ID: "upgrade",
|
AvailableActions: []*notifications.Action{
|
||||||
Text: "Upgrade Now",
|
{
|
||||||
Type: notifications.ActionTypeWebhook,
|
ID: "ack",
|
||||||
Payload: notifications.ActionTypeWebhookPayload{
|
Text: "OK",
|
||||||
Method: "POST",
|
},
|
||||||
URL: "updates/apply",
|
{
|
||||||
|
ID: "upgrade",
|
||||||
|
Text: "Upgrade Now",
|
||||||
|
Type: notifications.ActionTypeWebhook,
|
||||||
|
Payload: notifications.ActionTypeWebhookPayload{
|
||||||
|
Method: "POST",
|
||||||
|
URL: "updates/apply",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%w: apply updates to download and upgrade", ErrActionRequired)
|
return fmt.Errorf("%w: apply updates to download and upgrade", ErrActionRequired)
|
||||||
}
|
}
|
||||||
|
@ -307,6 +330,29 @@ func (u *Updater) updateAndUpgrade(w *mgr.WorkerCtx, indexURLs []string, ignoreV
|
||||||
|
|
||||||
// Notify user that a restart is required.
|
// Notify user that a restart is required.
|
||||||
if u.cfg.Notify && u.instance.Notifications() != nil {
|
if u.cfg.Notify && u.instance.Notifications() != nil {
|
||||||
|
|
||||||
|
u.instance.Notifications().Notify(¬ifications.Notification{
|
||||||
|
EventID: restartRequiredNotificationID,
|
||||||
|
Type: notifications.Info,
|
||||||
|
Title: "Restart Required",
|
||||||
|
Message: "Portmaster v" + downloader.index.Version + " is installed. Restart to use new version.",
|
||||||
|
AvailableActions: []*notifications.Action{
|
||||||
|
{
|
||||||
|
ID: "ack",
|
||||||
|
Text: "Later",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: "restart",
|
||||||
|
Text: "Restart Now",
|
||||||
|
Type: notifications.ActionTypeWebhook,
|
||||||
|
Payload: notifications.ActionTypeWebhookPayload{
|
||||||
|
Method: "POST",
|
||||||
|
URL: "updates/apply",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
u.instance.Notifications().NotifyInfo(
|
u.instance.Notifications().NotifyInfo(
|
||||||
updateAvailableNotificationID,
|
updateAvailableNotificationID,
|
||||||
"Restart Required",
|
"Restart Required",
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package updates
|
|
||||||
|
|
||||||
import "github.com/safing/jess"
|
|
||||||
|
|
||||||
var (
|
|
||||||
// BinarySigningKeys holds the signing keys in text format.
|
|
||||||
BinarySigningKeys = []string{
|
|
||||||
// Safing Code Signing Key #1
|
|
||||||
"recipient:public-ed25519-key:safing-code-signing-key-1:92bgBLneQUWrhYLPpBDjqHbpFPuNVCPAaivQ951A4aq72HcTiw7R1QmPJwFM1mdePAvEVDjkeb8S4fp2pmRCsRa8HrCvWQEjd88rfZ6TznJMfY4g7P8ioGFjfpyx2ZJ8WCZJG5Qt4Z9nkabhxo2Nbi3iywBTYDLSbP5CXqi7jryW7BufWWuaRVufFFzhwUC2ryWFWMdkUmsAZcvXwde4KLN9FrkWAy61fGaJ8GCwGnGCSitANnU2cQrsGBXZzxmzxwrYD",
|
|
||||||
// Safing Code Signing Key #2
|
|
||||||
"recipient:public-ed25519-key:safing-code-signing-key-2:92bgBLneQUWrhYLPpBDjqHbPC2d1o5JMyZFdavWBNVtdvbPfzDewLW95ScXfYPHd3QvWHSWCtB4xpthaYWxSkK1kYiGp68DPa2HaU8yQ5dZhaAUuV4Kzv42pJcWkCeVnBYqgGBXobuz52rFqhDJy3rz7soXEmYhJEJWwLwMeioK3VzN3QmGSYXXjosHMMNC76rjufSoLNtUQUWZDSnHmqbuxbKMCCsjFXUGGhtZVyb7bnu7QLTLk6SKHBJDMB6zdL9sw3",
|
|
||||||
}
|
|
||||||
|
|
||||||
// BinarySigningTrustStore is an in-memory trust store with the signing keys.
|
|
||||||
BinarySigningTrustStore = jess.NewMemTrustStore()
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
for _, signingKey := range BinarySigningKeys {
|
|
||||||
rcpt, err := jess.RecipientFromTextFormat(signingKey)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = BinarySigningTrustStore.StoreSignet(rcpt)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue