-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclipboard.go
39 lines (32 loc) · 829 Bytes
/
clipboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package utils
import (
"os"
"github.com/atotto/clipboard"
"github.com/rs/zerolog/log"
clipboardImage "github.com/skanehira/clipboard-image"
)
func WriteToClipboard(text string) {
err := clipboard.WriteAll(text)
if err != nil {
log.Error().Msg("Failed to write to clipboard")
}
}
func WriteToClipboardImage(bytes []byte) {
tempFilename := "/tmp/qr-image.png"
err := os.WriteFile(tempFilename, bytes, 0644)
if err != nil {
log.Fatal().Msg("Failed to write temp image for clipboard")
}
f, err := os.Open(tempFilename)
if err != nil {
log.Fatal().Msg("Failed to open temp image for clipboard")
}
defer f.Close()
if err = clipboardImage.CopyToClipboard(f); err != nil {
log.Fatal().Msg("Failed to copy to clipboard")
}
}
func ReadFromClipboard() string {
text, _ := clipboard.ReadAll()
return text
}