Skip to content

Commit de0c65a

Browse files
committed
Implement system UI Clipboard
1 parent 0278c3b commit de0c65a

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

flutter/flutter.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ func (flu *EngineOpenGL) EngineSendPlatformMessage(Message PlatformMessage) Resu
170170
return (Result)(res)
171171
}
172172

173+
func (flu *EngineOpenGL) EngineSendPlatformMessageResponse(respondTo *PlatformMessage, respondWith []byte) Result {
174+
175+
res := C.FlutterEngineSendPlatformMessageResponse(
176+
flu.Engine,
177+
(*C.FlutterPlatformMessageResponseHandle)(respondTo.ResponseHandle),
178+
(*C.uchar)(C.CBytes(respondWith)),
179+
C.ulong(len(respondWith)))
180+
181+
return (Result)(res)
182+
}
183+
173184
// EngineFlushPendingTasksNow flush tasks on a message loop not controlled by the Flutter engine.
174185
// deprecated soon.
175186
func EngineFlushPendingTasksNow() {

flutter/flutter_proxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func proxy_on_platform_message(message *C.FlutterPlatformMessage, userPointer un
2828

2929
FlutterPlatformMessage.Message = messageContent
3030
FlutterPlatformMessage.Channel = C.GoString(message.channel)
31+
FlutterPlatformMessage.ResponseHandle = (*platformMessageResponseHandle)(message.response_handle)
3132
if message.response_handle == nil {
3233
fmt.Println("==================== NIL")
3334
}

flutter/message.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const (
1818
TextInputClientSet = "TextInput.setClient"
1919
TextInputClientClear = "TextInput.clearClient"
2020
TextInputSetEditState = "TextInput.setEditingState"
21+
22+
// platform
23+
ClipboardSetData = "Clipboard.setData"
24+
ClipboardGetData = "Clipboard.getData"
2125
)
2226

2327
// Message is the json content of a PlatformMessage
@@ -44,3 +48,7 @@ type ArgsEditingState struct {
4448
ComposingBase int `json:"composingBase"`
4549
ComposingExtent int `json:"composingExtent"`
4650
}
51+
52+
type ArgsClipboardSetData struct {
53+
Text string `json:"text"`
54+
}

gutter.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,31 @@ func onPlatformMessage(platMessage flutter.PlatformMessage, window unsafe.Pointe
323323
default:
324324
// log.Printf("unhandled text input method: %#v\n", platMessage.Message)
325325
}
326+
} else if platMessage.Channel == flutter.PlatformChannel {
327+
switch message.Method {
328+
case flutter.ClipboardSetData:
329+
newClipboard := flutter.ArgsClipboardSetData{}
330+
json.Unmarshal(message.Args, &newClipboard)
331+
windows.SetClipboardString(newClipboard.Text)
332+
case flutter.ClipboardGetData:
333+
requestedMime := ""
334+
json.Unmarshal(message.Args, &requestedMime)
335+
if requestedMime == "text/plain" {
336+
flutterOGL := *(*flutter.EngineOpenGL)(windows.GetUserPointer())
337+
clipText, _ := windows.GetClipboardString()
338+
339+
retBytes, _ := json.Marshal([]struct {
340+
Text string `json:"text"`
341+
}{{clipText}})
342+
343+
flutterOGL.EngineSendPlatformMessageResponse(&platMessage, retBytes)
344+
} else {
345+
// log.Printf("Don't know how to acquire type #v from the clipboard", requestedMime)
346+
}
347+
348+
default:
349+
// log.Printf("unhandled platform method: %#v\n", platMessage.Message)
350+
}
326351
}
327352

328353
return true

0 commit comments

Comments
 (0)