io/router: remove panics in clipboardQueue

Since the Process* methods on clipboardQueue are called while decoding
the ops, no need to recheck for the op type.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2021-10-06 09:01:44 +02:00
committed by Elias Naur
parent e11ac9784c
commit 3c34a39d88
2 changed files with 5 additions and 13 deletions
+3 -11
View File
@@ -4,8 +4,6 @@ package router
import (
"gioui.org/io/event"
"gioui.org/internal/opconst"
)
type clipboardQueue struct {
@@ -29,7 +27,7 @@ func (q *clipboardQueue) WriteClipboard() (string, bool) {
// ReadClipboard reports if any new handler is waiting
// to read the clipboard.
func (q *clipboardQueue) ReadClipboard() bool {
if len(q.receivers) <= 0 || q.requested {
if len(q.receivers) == 0 || q.requested {
return false
}
q.requested = true
@@ -43,17 +41,11 @@ func (q *clipboardQueue) Push(e event.Event, events *handlerEvents) {
}
}
func (q *clipboardQueue) ProcessWriteClipboard(d []byte, refs []interface{}) {
if opconst.OpType(d[0]) != opconst.TypeClipboardWrite {
panic("invalid op")
}
func (q *clipboardQueue) ProcessWriteClipboard(refs []interface{}) {
q.text = refs[0].(*string)
}
func (q *clipboardQueue) ProcessReadClipboard(d []byte, refs []interface{}) {
if opconst.OpType(d[0]) != opconst.TypeClipboardRead {
panic("invalid op")
}
func (q *clipboardQueue) ProcessReadClipboard(refs []interface{}) {
if q.receivers == nil {
q.receivers = make(map[event.Tag]struct{})
}
+2 -2
View File
@@ -140,9 +140,9 @@ func (q *Router) collect() {
}
q.profHandlers[op.Tag] = struct{}{}
case opconst.TypeClipboardRead:
q.cqueue.ProcessReadClipboard(encOp.Data, encOp.Refs)
q.cqueue.ProcessReadClipboard(encOp.Refs)
case opconst.TypeClipboardWrite:
q.cqueue.ProcessWriteClipboard(encOp.Data, encOp.Refs)
q.cqueue.ProcessWriteClipboard(encOp.Refs)
}
}
}