This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to turn off notifications
- Loading branch information
Showing
6 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/safing/portbase/database/record" | ||
|
||
"github.com/safing/portbase/api/client" | ||
"github.com/safing/portbase/log" | ||
|
||
"github.com/tevino/abool" | ||
) | ||
|
||
var ( | ||
notificationsEnabled = abool.NewBool(true) | ||
promptsEnabled = abool.NewBool(true) | ||
) | ||
|
||
func configClient() { | ||
configOp := apiClient.Qsub("query config", handleConfigUpdate) | ||
configOp.EnableResuscitation() | ||
} | ||
|
||
func handleConfigUpdate(m *client.Message) { | ||
switch m.Type { | ||
case client.MsgError: | ||
log.Warningf("config: received error message: %s", string(m.RawValue)) | ||
case client.MsgDone: | ||
case client.MsgSuccess: | ||
case client.MsgOk, client.MsgUpdate, client.MsgNew: | ||
|
||
// only process these keys | ||
switch m.Key { | ||
case "config:core/useSystemNotifications": | ||
case "config:filter/askWithSystemNotifications": | ||
default: | ||
return | ||
} | ||
|
||
// parse record | ||
if len(m.RawValue) < 2 { | ||
log.Warningf("notify: failed to parse new config msg %s: too short", m.Key) | ||
return | ||
} | ||
r, err := record.NewWrapper(m.Key, nil, m.RawValue[0], m.RawValue[1:]) | ||
if err != nil { | ||
log.Warningf("notify: failed to parse new config msg %s: %s", m.Key, err) | ||
return | ||
} | ||
acc := r.GetAccessor(r) | ||
|
||
// get value | ||
newValue, ok := acc.GetBool("Value") | ||
if !ok { | ||
newValue, ok = acc.GetBool("DefaultValue") | ||
if !ok { | ||
log.Warningf("config: could not get Value or DefaultValue from %s", m.Key) | ||
} | ||
} | ||
|
||
// set value | ||
switch m.Key { | ||
case "config:core/useSystemNotifications": | ||
notificationsEnabled.SetTo(newValue) | ||
log.Infof("config: use system notifications set to: %v", newValue) | ||
case "config:filter/askWithSystemNotifications": | ||
promptsEnabled.SetTo(newValue) | ||
log.Infof("config: ask with systemNotifications set to: %v", newValue) | ||
} | ||
|
||
case client.MsgDelete: | ||
case client.MsgWarning: | ||
case client.MsgOffline: | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters