Skip to content

Commit

Permalink
Remove clipboard from the Driver intterface
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre committed Sep 9, 2024
1 parent 55c6d11 commit f4cbbdd
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 36 deletions.
13 changes: 7 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
var _ fyne.App = (*fyneApp)(nil)

type fyneApp struct {
driver fyne.Driver
icon fyne.Resource
uniqueID string
driver fyne.Driver
clipboard fyne.Clipboard
icon fyne.Resource
uniqueID string

cloud fyne.CloudProvider
lifecycle app.Lifecycle
Expand Down Expand Up @@ -110,7 +111,7 @@ func (a *fyneApp) newDefaultPreferences() *preferences {
}

func (a *fyneApp) Clipboard() fyne.Clipboard {
return a.Driver().Clipboard()
return a.clipboard
}

// New returns a new application instance with the default driver and no unique ID (unless specified in FyneApp.toml)
Expand Down Expand Up @@ -141,8 +142,8 @@ func makeStoreDocs(id string, s *store) *internal.Docs {
}
}

func newAppWithDriver(d fyne.Driver, id string) fyne.App {
newApp := &fyneApp{uniqueID: id, driver: d}
func newAppWithDriver(d fyne.Driver, clipboard fyne.Clipboard, id string) fyne.App {
newApp := &fyneApp{uniqueID: id, clipboard: clipboard, driver: d}
fyne.SetCurrentApp(newApp)

newApp.prefs = newApp.newDefaultPreferences()
Expand Down
2 changes: 1 addition & 1 deletion app/app_gl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
// NewWithID returns a new app instance using the appropriate runtime driver.
// The ID string should be globally unique to this app.
func NewWithID(id string) fyne.App {
return newAppWithDriver(glfw.NewGLDriver(), id)
return newAppWithDriver(glfw.NewGLDriver(), &glfw.Clipboard{}, id)
}
2 changes: 1 addition & 1 deletion app/app_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// The ID string should be globally unique to this app.
func NewWithID(id string) fyne.App {
d := mobile.NewGoMobileDriver()
a := newAppWithDriver(d, id)
a := newAppWithDriver(d, &mobile.MobileClipboard{}, id)
d.(mobile.ConfiguredDriver).SetOnConfigurationChanged(func(c *mobile.Configuration) {
internalapp.SystemTheme = c.SystemTheme

Expand Down
5 changes: 0 additions & 5 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ type Driver interface {
//
// Since: 2.5
SetDisableScreenBlanking(bool)

// Clipboard returns the system clipboard.
//
// Since: 2.6
Clipboard() Clipboard
}
14 changes: 7 additions & 7 deletions internal/driver/glfw/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
)

// Declare conformity with Clipboard interface
var _ fyne.Clipboard = (*clipboard)(nil)
var _ fyne.Clipboard = (*Clipboard)(nil)

// clipboard represents the system clipboard
type clipboard struct{}
// Clipboard represents the system Clipboard
type Clipboard struct{}

// Content returns the clipboard content
func (c *clipboard) Content() string {
func (c *Clipboard) Content() string {
// This retry logic is to work around the "Access Denied" error often thrown in windows PR#1679
if runtime.GOOS != "windows" {
return c.content()
Expand All @@ -34,7 +34,7 @@ func (c *clipboard) Content() string {
return ""
}

func (c *clipboard) content() string {
func (c *Clipboard) content() string {
content := ""
runOnMain(func() {
content = glfw.GetClipboardString()
Expand All @@ -43,7 +43,7 @@ func (c *clipboard) content() string {
}

// SetContent sets the clipboard content
func (c *clipboard) SetContent(content string) {
func (c *Clipboard) SetContent(content string) {
// This retry logic is to work around the "Access Denied" error often thrown in windows PR#1679
if runtime.GOOS != "windows" {
c.setContent(content)
Expand All @@ -59,7 +59,7 @@ func (c *clipboard) SetContent(content string) {
fyne.LogError("GLFW clipboard set failed", nil)
}

func (c *clipboard) setContent(content string) {
func (c *Clipboard) setContent(content string) {
runOnMain(func() {
glfw.SetClipboardString(content)
})
Expand Down
4 changes: 0 additions & 4 deletions internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func toOSIcon(icon []byte) ([]byte, error) {
return buf.Bytes(), nil
}

func (d *gLDriver) Clipboard() fyne.Clipboard {
return &clipboard{}
}

func (d *gLDriver) RenderedTextSize(text string, textSize float32, style fyne.TextStyle, source fyne.Resource) (size fyne.Size, baseline float32) {
return painter.RenderedTextSize(text, textSize, style, source)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (w *window) ShowAndRun() {

// Clipboard returns the system clipboard
func (w *window) Clipboard() fyne.Clipboard {
return &clipboard{}
return &Clipboard{}
}

func (w *window) Content() fyne.CanvasObject {
Expand Down
6 changes: 3 additions & 3 deletions internal/driver/mobile/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

// Declare conformity with Clipboard interface
var _ fyne.Clipboard = (*mobileClipboard)(nil)
var _ fyne.Clipboard = (*MobileClipboard)(nil)

// mobileClipboard represents the system mobileClipboard
type mobileClipboard struct {
// MobileClipboard represents the system MobileClipboard
type MobileClipboard struct {
}
4 changes: 2 additions & 2 deletions internal/driver/mobile/clipboard_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// Content returns the clipboard content for Android
func (c *mobileClipboard) Content() string {
func (c *MobileClipboard) Content() string {
content := ""
app.RunOnJVM(func(vm, env, ctx uintptr) error {
chars := C.getClipboardContent(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx))
Expand All @@ -34,7 +34,7 @@ func (c *mobileClipboard) Content() string {
}

// SetContent sets the clipboard content for Android
func (c *mobileClipboard) SetContent(content string) {
func (c *MobileClipboard) SetContent(content string) {
contentStr := C.CString(content)
defer C.free(unsafe.Pointer(contentStr))

Expand Down
4 changes: 2 additions & 2 deletions internal/driver/mobile/clipboard_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package mobile
import "fyne.io/fyne/v2"

// Content returns the clipboard content for mobile simulator runs
func (c *mobileClipboard) Content() string {
func (c *MobileClipboard) Content() string {
fyne.LogError("Clipboard is not supported in mobile simulation", nil)
return ""
}

// SetContent sets the clipboard content for mobile simulator runs
func (c *mobileClipboard) SetContent(content string) {
func (c *MobileClipboard) SetContent(content string) {
fyne.LogError("Clipboard is not supported in mobile simulation", nil)
}
4 changes: 2 additions & 2 deletions internal/driver/mobile/clipboard_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import "C"
import "unsafe"

// Content returns the clipboard content for iOS
func (c *mobileClipboard) Content() string {
func (c *MobileClipboard) Content() string {
content := C.getClipboardContent()

return C.GoString(content)
}

// SetContent sets the clipboard content for iOS
func (c *mobileClipboard) SetContent(content string) {
func (c *MobileClipboard) SetContent(content string) {
contentStr := C.CString(content)
defer C.free(unsafe.Pointer(contentStr))

Expand Down
2 changes: 1 addition & 1 deletion internal/driver/mobile/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (d *driver) currentWindow() *window {
}

func (d *driver) Clipboard() fyne.Clipboard {
return &mobileClipboard{}
return &MobileClipboard{}
}

func (d *driver) RenderedTextSize(text string, textSize float32, style fyne.TextStyle, source fyne.Resource) (size fyne.Size, baseline float32) {
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/mobile/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (w *window) Canvas() fyne.Canvas {

func (w *window) Clipboard() fyne.Clipboard {
if w.clipboard == nil {
w.clipboard = &mobileClipboard{}
w.clipboard = &MobileClipboard{}
}
return w.clipboard
}
Expand Down

0 comments on commit f4cbbdd

Please sign in to comment.