diff --git a/core/events.go b/core/events.go index 908347fd..8f1fd446 100644 --- a/core/events.go +++ b/core/events.go @@ -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 } diff --git a/updates/upgrader.go b/updates/upgrader.go index d6a8e0b2..e4bb75a1 100644 --- a/updates/upgrader.go +++ b/updates/upgrader.go @@ -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 {