mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Add buttons to core upgrade notification
This commit is contained in:
parent
9bc3f95e9e
commit
bdf2d025b1
2 changed files with 33 additions and 2 deletions
|
@ -32,15 +32,19 @@ func registerEventHooks() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shutdown shuts the Portmaster down.
|
||||||
func shutdown(ctx context.Context, _ interface{}) error {
|
func shutdown(ctx context.Context, _ interface{}) error {
|
||||||
log.Warning("core: user requested shutdown")
|
log.Warning("core: user requested shutdown")
|
||||||
|
// Do not use a worker, as this would block itself here.
|
||||||
go modules.Shutdown() //nolint:errcheck
|
go modules.Shutdown() //nolint:errcheck
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restart restarts the Portmaster.
|
||||||
func restart(ctx context.Context, data interface{}) error {
|
func restart(ctx context.Context, data interface{}) error {
|
||||||
log.Info("core: user requested restart")
|
log.Info("core: user requested restart")
|
||||||
modules.SetExitStatusCode(restartCode)
|
modules.SetExitStatusCode(restartCode)
|
||||||
|
// Do not use a worker, as this would block itself here.
|
||||||
go modules.Shutdown() //nolint:errcheck
|
go modules.Shutdown() //nolint:errcheck
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,10 +84,19 @@ func upgradeCoreNotify() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.GetInfo().Version != pmCoreUpdate.Version() {
|
if info.GetInfo().Version != pmCoreUpdate.Version() {
|
||||||
notifications.NotifyInfo(
|
n := notifications.NotifyInfo(
|
||||||
"updates-core-update-available",
|
"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()),
|
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")
|
log.Debugf("updates: new portmaster version available, sending notification to user")
|
||||||
}
|
}
|
||||||
|
@ -95,6 +104,24 @@ func upgradeCoreNotify() error {
|
||||||
return nil
|
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 {
|
func upgradePortmasterControl() error {
|
||||||
filename := "portmaster-control"
|
filename := "portmaster-control"
|
||||||
if onWindows {
|
if onWindows {
|
||||||
|
|
Loading…
Add table
Reference in a new issue