[v3 windows] Add clipboard support

This commit is contained in:
Lea Anthony 2023-06-10 13:01:10 +10:00
commit 833671d30c
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
3 changed files with 21 additions and 20 deletions

View file

@ -2,7 +2,7 @@ package application
type clipboardImpl interface {
setText(text string) bool
text() string
text() (string, bool)
}
type Clipboard struct {
@ -19,6 +19,6 @@ func (c *Clipboard) SetText(text string) bool {
return c.impl.setText(text)
}
func (c *Clipboard) Text() string {
func (c *Clipboard) Text() (string, bool) {
return c.impl.text()
}

View file

@ -43,12 +43,12 @@ func (m macosClipboard) setText(text string) bool {
return bool(success)
}
func (m macosClipboard) text() string {
func (m macosClipboard) text() (string, bool) {
clipboardLock.RLock()
defer clipboardLock.RUnlock()
clipboardText := C.getClipboardText()
result := C.GoString(clipboardText)
return result
return result, true
}
func newClipboardImpl() *macosClipboard {

View file

@ -2,25 +2,26 @@
package application
type windowsClipboard struct{}
import (
"github.com/wailsapp/wails/v3/pkg/w32"
"sync"
)
func (m windowsClipboard) setText(text string) bool {
//clipboardLock.Lock()
//defer clipboardLock.Unlock()
//cText := C.CString(text)
//success := C.setClipboardText(cText)
//C.free(unsafe.Pointer(cText))
//return bool(success)
panic("implement me")
type windowsClipboard struct {
lock sync.RWMutex
}
func (m windowsClipboard) text() string {
//clipboardLock.RLock()
//defer clipboardLock.RUnlock()
//clipboardText := C.getClipboardText()
//result := C.GoString(clipboardText)
//return result
panic("implement me")
func (m *windowsClipboard) setText(text string) bool {
m.lock.Lock()
defer m.lock.Unlock()
return w32.SetClipboardText(text) == nil
}
func (m *windowsClipboard) text() (string, bool) {
m.lock.Lock()
defer m.lock.Unlock()
text, err := w32.GetClipboardText()
return text, err == nil
}
func newClipboardImpl() *windowsClipboard {