Skip to content

Implement system UI Clipboard #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Run(options ...Option) (err error) {
// The Windows Title Handler and the TextInput handler come by default
options = append(options, addHandlerWindowTitle())
options = append(options, addHandlerTextInput())
options = append(options, addHandlerClipboard())

c = c.merge(options...)

Expand Down
41 changes: 41 additions & 0 deletions system_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const (
platformChannel = "flutter/platform"
// Args -> struct ArgsAppSwitcherDescription
setDescriptionMethod = "SystemChrome.setApplicationSwitcherDescription"

clipboardSetData = "Clipboard.setData"
clipboardGetData = "Clipboard.getData"
)

// ArgsAppSwitcherDescription Args content
Expand Down Expand Up @@ -50,6 +53,44 @@ func addHandlerWindowTitle() Option {

}

func addHandlerClipboard() Option {
handler := func(platMessage flutter.PlatformMessage,
flutterEngine *flutter.EngineOpenGL,
window *glfw.Window) bool {

message := platMessage.Message
switch message.Method {
case clipboardSetData:
newClipboard := struct {
Text string `json:"text"`
}{}
json.Unmarshal(message.Args, &newClipboard)
window.SetClipboardString(newClipboard.Text)
case clipboardGetData:
requestedMime := ""
json.Unmarshal(message.Args, &requestedMime)
if requestedMime == "text/plain" {
clipText, _ := window.GetClipboardString()

retBytes, _ := json.Marshal([]struct {
Text string `json:"text"`
}{{clipText}})

flutterEngine.SendPlatformMessageResponse(platMessage, retBytes)
return true
} else {
// log.Printf("Don't know how to acquire type #v from the clipboard", requestedMime)
}

default:
// log.Printf("unhandled platform method: %#v\n", platMessage.Message)
}
return false

}
return OptionAddPluginReceiver(handler, platformChannel)
}

/////////////////
// TextInput //
/////////////////
Expand Down