Skip to content

Commit

Permalink
[feat] Add option to disable notification icon (#2845)
Browse files Browse the repository at this point in the history
* [feat] Add option to disable notification icon

Fixes #2810

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>

* [chore] Document new config option

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>

---------

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz committed Mar 29, 2024
1 parent 311a6ed commit 9b41761
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ This is a list of available options:
| `generate.strict` | `bool` | Use strict mode for generated password. | `false` |
| `generate.symbols` | `bool` | Include symbols in generated password. | `false` |
| `mounts.path` | `string` | Path to the root store. | `$XDG_DATA_HOME/gopass/stores/root` |
| `notify.disable-icon` | `bool` | Do not show notification icon (not available on every platform). |
| `recipients.check` | `bool` | Check recipients hash. The global config option takes precedence over local ones here for security reasons. | `false` |
| `recipients.hash` | `string` | SHA256 hash of the recipients file. Used to notify the user when the recipients files change. Not set, nor read at the local level for security reasons. | `` |
| `recipients.remove-extra-keys` | `bool` | Remove extra recipients during key import. Not supported at the local level for security reasons. | `false` |
Expand Down
8 changes: 7 additions & 1 deletion internal/notify/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ package notify
import (
"bytes"
"compress/gzip"
"context"
"io"
"os"
"path/filepath"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/pkg/appdir"
"github.com/gopasspw/gopass/pkg/fsutil"
)

func iconURI() string {
func iconURI(ctx context.Context) string {
if config.Bool(ctx, "notify.disable-icon") {
return ""
}

userCache := appdir.UserCache()
if !fsutil.IsDir(userCache) {
if err := os.MkdirAll(userCache, 0o755); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/notify/notify_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Notify(ctx context.Context, subj, msg string) error {
// check if terminal-notifier was installed else use the applescript fallback
tn, _ := executableExists(terminalNotifier)
if tn {
return tnNotification(msg, subj)
return tnNotification(ctx, msg, subj)
}

return osaNotification(msg, subj)
Expand All @@ -53,8 +53,8 @@ func execNotification(executable string, args []string) error {
}

// display notification with terminal-notifier.
func tnNotification(msg string, subj string) error {
arguments := []string{"-title", "Gopass", "-message", msg, "-subtitle", subj, "-appIcon", iconURI()}
func tnNotification(ctx context.Context, msg string, subj string) error {
arguments := []string{"-title", "Gopass", "-message", msg, "-subtitle", subj, "-appIcon", iconURI(ctx)}

return execNotification(terminalNotifier, arguments)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/notify/notify_dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Notify(ctx context.Context, subj, msg string) error {
}

obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call("org.freedesktop.Notifications.Notify", 0, "gopass", uint32(0), iconURI(), subj, msg, []string{}, map[string]dbus.Variant{"transient": dbus.MakeVariant(true)}, int32(3000))
call := obj.Call("org.freedesktop.Notifications.Notify", 0, "gopass", uint32(0), iconURI(ctx), subj, msg, []string{}, map[string]dbus.Variant{"transient": dbus.MakeVariant(true)}, int32(3000))
if call.Err != nil {
debug.Log("DBus notification failure: %s", call.Err)

Expand Down
7 changes: 5 additions & 2 deletions internal/notify/notify_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package notify

import (
"context"
"image/png"
"os"
"strings"
Expand All @@ -20,9 +21,11 @@ func TestNotify(t *testing.T) {
func TestIcon(t *testing.T) {
t.Parallel()

fn := strings.TrimPrefix(iconURI(), "file://")
ctx := context.Background()

fn := strings.TrimPrefix(iconURI(ctx), "file://")
require.NoError(t, os.Remove(fn))
_ = iconURI()
_ = iconURI(ctx)
fh, err := os.Open(fn)
require.NoError(t, err)

Expand Down

0 comments on commit 9b41761

Please sign in to comment.