diff --git a/docs/config.md b/docs/config.md index c583ecc0b8..d25735be27 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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` | diff --git a/internal/notify/icon.go b/internal/notify/icon.go index 60f11b7988..7b122278b0 100644 --- a/internal/notify/icon.go +++ b/internal/notify/icon.go @@ -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 { diff --git a/internal/notify/notify_darwin.go b/internal/notify/notify_darwin.go index 482c635911..610691a016 100644 --- a/internal/notify/notify_darwin.go +++ b/internal/notify/notify_darwin.go @@ -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) @@ -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) } diff --git a/internal/notify/notify_dbus.go b/internal/notify/notify_dbus.go index 89258b4b36..9191718e5f 100644 --- a/internal/notify/notify_dbus.go +++ b/internal/notify/notify_dbus.go @@ -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) diff --git a/internal/notify/notify_test.go b/internal/notify/notify_test.go index cddf6c012e..217502a6a8 100644 --- a/internal/notify/notify_test.go +++ b/internal/notify/notify_test.go @@ -1,6 +1,7 @@ package notify import ( + "context" "image/png" "os" "strings" @@ -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)