Add buttons to core upgrade notification

This commit is contained in:
Daniel 2020-07-21 16:56:45 +02:00
parent 9bc3f95e9e
commit bdf2d025b1
2 changed files with 33 additions and 2 deletions

View file

@ -32,15 +32,19 @@ func registerEventHooks() error {
return nil
}
// shutdown shuts the Portmaster down.
func shutdown(ctx context.Context, _ interface{}) error {
log.Warning("core: user requested shutdown")
// Do not use a worker, as this would block itself here.
go modules.Shutdown() //nolint:errcheck
return nil
}
// restart restarts the Portmaster.
func restart(ctx context.Context, data interface{}) error {
log.Info("core: user requested restart")
modules.SetExitStatusCode(restartCode)
// Do not use a worker, as this would block itself here.
go modules.Shutdown() //nolint:errcheck
return nil
}

View file

@ -84,10 +84,19 @@ func upgradeCoreNotify() error {
}
if info.GetInfo().Version != pmCoreUpdate.Version() {
notifications.NotifyInfo(
"updates-core-update-available",
n := notifications.NotifyInfo(
"updates:core-update-available",
fmt.Sprintf("There is an update available for the Portmaster core (v%s), please restart the Portmaster to apply the update.", pmCoreUpdate.Version()),
notifications.Action{
ID: "later",
Text: "Later",
},
notifications.Action{
ID: "restart",
Text: "Restart Portmaster Now",
},
)
n.SetActionFunction(upgradeCoreNotifyActionHandler)
log.Debugf("updates: new portmaster version available, sending notification to user")
}
@ -95,6 +104,24 @@ func upgradeCoreNotify() error {
return nil
}
func upgradeCoreNotifyActionHandler(n *notifications.Notification) {
switch n.SelectedActionID {
case "restart":
// Cannot directly trigger due to import loop.
err := module.InjectEvent(
"user triggered restart via notification",
"core",
"restart",
nil,
)
if err != nil {
log.Warningf("updates: failed to trigger restart via notification: %s", err)
}
case "later":
n.Expires = time.Now().Unix() // expire immediately
}
}
func upgradePortmasterControl() error {
filename := "portmaster-control"
if onWindows {