forked from gmp/clip
1
0
Fork 0
clip/main.go

78 lines
1.3 KiB
Go
Raw Permalink Normal View History

2019-10-01 09:33:35 -04:00
package clip
import (
"strings"
"git.wow.st/63l06ri5/clip/ns"
2019-10-01 09:33:35 -04:00
)
var pb *ns.NSPasteboard
const (
uriPrefix = "file://"
uriPrefixLength = len(uriPrefix)
)
2019-10-01 09:33:35 -04:00
func Clear() {
if pb == nil {
pb = ns.NSPasteboardGeneralPasteboard()
}
pb.ClearContents()
}
func Set(x string) bool {
if pb == nil {
pb = ns.NSPasteboardGeneralPasteboard()
}
pb.ClearContents()
return pb.SetString(x)
}
func Get() string {
if pb == nil {
pb = ns.NSPasteboardGeneralPasteboard()
}
ret := pb.GetString()
if ret.Ptr() == nil {
return ""
} else {
return ret.String()
}
}
func PasteFileList(filePaths []string) {
if pb == nil {
pb = ns.NSPasteboardGeneralPasteboard()
}
2021-02-01 09:34:13 -05:00
pb.ClearContents()
pb.PasteFileList(filePaths)
}
func GetFileList() []string {
if pb == nil {
pb = ns.NSPasteboardGeneralPasteboard()
}
ret := pb.GetFileList()
result := make([]string, 0)
if ret.Ptr() == nil {
return result
} else {
filesStr := ret.String()
2021-02-01 10:09:47 -05:00
arr := strings.Split(filesStr, ns.FilesDelimeter)
for _, item := range arr {
if strings.HasPrefix(item, uriPrefix) {
result = append(result, item[uriPrefixLength:])
}
}
return result
}
}
func GetImage(pathToStore string) bool {
if pb == nil {
pb = ns.NSPasteboardGeneralPasteboard()
}
return pb.GetImage(pathToStore)
}