mirror of
https://github.com/safing/portbase
synced 2025-04-23 10:49:09 +00:00
Move useSystemNotifications to notifications module, apply on save
This commit is contained in:
parent
412a393bca
commit
8a9ee6e2ca
3 changed files with 46 additions and 2 deletions
notifications
32
notifications/config.go
Normal file
32
notifications/config.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package notifications
|
||||
|
||||
import (
|
||||
"github.com/safing/portbase/config"
|
||||
)
|
||||
|
||||
// Configuration Keys.
|
||||
var (
|
||||
CfgUseSystemNotificationsKey = "core/useSystemNotifications"
|
||||
useSystemNotifications config.BoolOption
|
||||
)
|
||||
|
||||
func registerConfig() error {
|
||||
if err := config.Register(&config.Option{
|
||||
Name: "Desktop Notifications",
|
||||
Key: CfgUseSystemNotificationsKey,
|
||||
Description: "In addition to showing notifications in the Portmaster App, also send them to the Desktop. This requires the Portmaster Notifier to be running.",
|
||||
OptType: config.OptTypeBool,
|
||||
ExpertiseLevel: config.ExpertiseLevelUser,
|
||||
ReleaseLevel: config.ReleaseLevelStable,
|
||||
DefaultValue: true, // TODO: turn off by default on unsupported systems
|
||||
Annotations: config.Annotations{
|
||||
config.DisplayOrderAnnotation: -15,
|
||||
config.CategoryAnnotation: "User Interface",
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
useSystemNotifications = config.Concurrent.GetAsBool(CfgUseSystemNotificationsKey, true)
|
||||
|
||||
return nil
|
||||
}
|
|
@ -11,7 +11,11 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
module = modules.Register("notifications", nil, start, nil, "database", "base")
|
||||
module = modules.Register("notifications", prep, start, nil, "database", "base")
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
return registerConfig()
|
||||
}
|
||||
|
||||
func start() error {
|
||||
|
|
|
@ -75,6 +75,8 @@ type Notification struct {
|
|||
// ShowOnSystem specifies if the notification should be also shown on the
|
||||
// operating system. Notifications shown on the operating system level are
|
||||
// more focus-intrusive and should only be used for important notifications.
|
||||
// If the configuration option "Desktop Notifications" is switched off, this
|
||||
// will be forced to false on the first save.
|
||||
ShowOnSystem bool
|
||||
// EventData contains an additional payload for the notification. This payload
|
||||
// may contain contextual data and may be used by a localization framework
|
||||
|
@ -319,9 +321,15 @@ func (n *Notification) save(pushUpdate bool) {
|
|||
n.State = Active
|
||||
}
|
||||
|
||||
// check key
|
||||
// Initialize on first save.
|
||||
if !n.KeyIsSet() {
|
||||
// Set database key.
|
||||
n.SetKey(fmt.Sprintf("notifications:all/%s", n.EventID))
|
||||
|
||||
// Check if notifications should be shown on the system at all.
|
||||
if !useSystemNotifications() {
|
||||
n.ShowOnSystem = false
|
||||
}
|
||||
}
|
||||
|
||||
// Update meta data.
|
||||
|
|
Loading…
Add table
Reference in a new issue