Migrate notifier from portmaster-ui to cmds/notifier, remove some duplicated code, move assets to assets/data and add a small go package in assets to allow embedding icons
This commit is contained in:
50
cmds/notifier/shutdown.go
Normal file
50
cmds/notifier/shutdown.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/safing/portbase/api/client"
|
||||
"github.com/safing/portbase/log"
|
||||
)
|
||||
|
||||
func startShutdownEventListener() {
|
||||
shutdownNotifOp := apiClient.Sub("query runtime:modules/core/event/shutdown", handleShutdownEvent)
|
||||
shutdownNotifOp.EnableResuscitation()
|
||||
|
||||
restartNotifOp := apiClient.Sub("query runtime:modules/core/event/restart", handleRestartEvent)
|
||||
restartNotifOp.EnableResuscitation()
|
||||
}
|
||||
|
||||
func handleShutdownEvent(m *client.Message) {
|
||||
switch m.Type {
|
||||
case client.MsgOk, client.MsgUpdate, client.MsgNew:
|
||||
shuttingDown.Set()
|
||||
triggerTrayUpdate()
|
||||
|
||||
log.Warningf("shutdown: received shutdown event, shutting down now")
|
||||
|
||||
// wait for the API client connection to die
|
||||
<-apiClient.Offline()
|
||||
shuttingDown.UnSet()
|
||||
|
||||
cancelMainCtx()
|
||||
|
||||
case client.MsgWarning, client.MsgError:
|
||||
log.Errorf("shutdown: event subscription error: %s", string(m.RawValue))
|
||||
}
|
||||
}
|
||||
|
||||
func handleRestartEvent(m *client.Message) {
|
||||
switch m.Type {
|
||||
case client.MsgOk, client.MsgUpdate, client.MsgNew:
|
||||
restarting.Set()
|
||||
triggerTrayUpdate()
|
||||
|
||||
log.Warningf("restart: received restart event")
|
||||
|
||||
// wait for the API client connection to die
|
||||
<-apiClient.Offline()
|
||||
restarting.UnSet()
|
||||
triggerTrayUpdate()
|
||||
case client.MsgWarning, client.MsgError:
|
||||
log.Errorf("shutdown: event subscription error: %s", string(m.RawValue))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user