commit e50dc197549ede1a4171027f01dd801d6b69705a
parent ca112cd4ad35741db8f0974f0d9d7a28cc8cdbb2
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Thu, 16 Jan 2025 19:58:01 +0800
notify: move helpers to common
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
2 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/notify_common.go b/notify_common.go
@@ -1,6 +1,7 @@
package nativenotify
import (
+ "encoding/hex"
"sync"
"sync/atomic"
)
@@ -25,3 +26,23 @@ func callbacksTake(m *sync.Map, id string) (Callback, bool) {
func callbacksPut(m *sync.Map, id string, fn Callback) {
m.Store(id, fn)
}
+
+// take returns the first element.
+func take[S ~[]E, E any](s *S) (e E, ok bool) {
+ if len(*s) == 0 {
+ return e, false
+ }
+ defer func() { *s = (*s)[1:] }()
+ return (*s)[0], true
+}
+
+// decode from hex.
+func decode(s string) string {
+ b, _ := hex.DecodeString(s)
+ return string(b)
+}
+
+// encode to hex.
+func encode(s string) string {
+ return hex.EncodeToString([]byte(s))
+}
diff --git a/notify_windows.go b/notify_windows.go
@@ -1,7 +1,6 @@
package nativenotify
import (
- "encoding/hex"
"fmt"
"strconv"
"strings"
@@ -102,21 +101,3 @@ func push(n Notification) (err error) {
return tn.Push()
}
-
-// take returns the first element.
-func take[S ~[]E, E any](s *S) (e E, ok bool) {
- if len(*s) == 0 {
- return e, false
- }
- defer func() { *s = (*s)[1:] }()
- return (*s)[0], true
-}
-
-func decode(s string) string {
- b, _ := hex.DecodeString(s)
- return string(b)
-}
-
-func encode(s string) string {
- return hex.EncodeToString([]byte(s))
-}