@@ -20,6 +20,9 @@ const (
20
20
platformChannel = "flutter/platform"
21
21
// Args -> struct ArgsAppSwitcherDescription
22
22
setDescriptionMethod = "SystemChrome.setApplicationSwitcherDescription"
23
+
24
+ clipboardSetData = "Clipboard.setData"
25
+ clipboardGetData = "Clipboard.getData"
23
26
)
24
27
25
28
// ArgsAppSwitcherDescription Args content
@@ -50,6 +53,44 @@ func addHandlerWindowTitle() Option {
50
53
51
54
}
52
55
56
+ func addHandlerClipboard () Option {
57
+ handler := func (platMessage flutter.PlatformMessage ,
58
+ flutterEngine * flutter.EngineOpenGL ,
59
+ window * glfw.Window ) bool {
60
+
61
+ message := platMessage .Message
62
+ switch message .Method {
63
+ case clipboardSetData :
64
+ newClipboard := struct {
65
+ Text string `json:"text"`
66
+ }{}
67
+ json .Unmarshal (message .Args , & newClipboard )
68
+ window .SetClipboardString (newClipboard .Text )
69
+ case clipboardGetData :
70
+ requestedMime := ""
71
+ json .Unmarshal (message .Args , & requestedMime )
72
+ if requestedMime == "text/plain" {
73
+ clipText , _ := window .GetClipboardString ()
74
+
75
+ retBytes , _ := json .Marshal ([]struct {
76
+ Text string `json:"text"`
77
+ }{{clipText }})
78
+
79
+ flutterEngine .SendPlatformMessageResponse (platMessage , retBytes )
80
+ return true
81
+ } else {
82
+ // log.Printf("Don't know how to acquire type #v from the clipboard", requestedMime)
83
+ }
84
+
85
+ default :
86
+ // log.Printf("unhandled platform method: %#v\n", platMessage.Message)
87
+ }
88
+ return false
89
+
90
+ }
91
+ return OptionAddPluginReceiver (handler , platformChannel )
92
+ }
93
+
53
94
/////////////////
54
95
// TextInput //
55
96
/////////////////
0 commit comments