mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
app/internal/window: [wasm] implement clipboard
Update gio#31 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -19,10 +19,12 @@ import (
|
|||||||
|
|
||||||
type window struct {
|
type window struct {
|
||||||
window js.Value
|
window js.Value
|
||||||
|
clipboard js.Value
|
||||||
cnv js.Value
|
cnv js.Value
|
||||||
tarea js.Value
|
tarea js.Value
|
||||||
w Callbacks
|
w Callbacks
|
||||||
redraw js.Func
|
redraw js.Func
|
||||||
|
clipboardCallback js.Func
|
||||||
requestAnimationFrame js.Value
|
requestAnimationFrame js.Value
|
||||||
cleanfuncs []func()
|
cleanfuncs []func()
|
||||||
touches []js.Value
|
touches []js.Value
|
||||||
@@ -43,15 +45,21 @@ func NewWindow(win Callbacks, opts *Options) error {
|
|||||||
tarea := createTextArea(doc)
|
tarea := createTextArea(doc)
|
||||||
cont.Call("appendChild", tarea)
|
cont.Call("appendChild", tarea)
|
||||||
w := &window{
|
w := &window{
|
||||||
cnv: cnv,
|
cnv: cnv,
|
||||||
tarea: tarea,
|
tarea: tarea,
|
||||||
window: js.Global().Get("window"),
|
window: js.Global().Get("window"),
|
||||||
|
clipboard: js.Global().Get("navigator").Get("clipboard"),
|
||||||
}
|
}
|
||||||
w.requestAnimationFrame = w.window.Get("requestAnimationFrame")
|
w.requestAnimationFrame = w.window.Get("requestAnimationFrame")
|
||||||
w.redraw = w.funcOf(func(this js.Value, args []js.Value) interface{} {
|
w.redraw = w.funcOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
w.animCallback()
|
w.animCallback()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
w.clipboardCallback = w.funcOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
|
content := args[0].String()
|
||||||
|
win.Event(system.ClipboardEvent{Text: content})
|
||||||
|
return nil
|
||||||
|
})
|
||||||
w.addEventListeners()
|
w.addEventListeners()
|
||||||
w.w = win
|
w.w = win
|
||||||
go func() {
|
go func() {
|
||||||
@@ -343,6 +351,26 @@ func (w *window) SetAnimating(anim bool) {
|
|||||||
w.animating = anim
|
w.animating = anim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *window) ReadClipboard() {
|
||||||
|
if w.clipboard.IsUndefined() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if w.clipboard.Get("readText").IsUndefined() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.clipboard.Call("readText", w.clipboard).Call("then", w.clipboardCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *window) WriteClipboard(s string) {
|
||||||
|
if w.clipboard.IsUndefined() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if w.clipboard.Get("writeText").IsUndefined() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.clipboard.Call("writeText", s)
|
||||||
|
}
|
||||||
|
|
||||||
func (w *window) ShowTextInput(show bool) {
|
func (w *window) ShowTextInput(show bool) {
|
||||||
// Run in a goroutine to avoid a deadlock if the
|
// Run in a goroutine to avoid a deadlock if the
|
||||||
// focus change result in an event.
|
// focus change result in an event.
|
||||||
|
|||||||
Reference in New Issue
Block a user