From 3c34a39d88bcbddb23e97342c396f6ad1015dd7a Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Wed, 6 Oct 2021 09:01:44 +0200 Subject: [PATCH] 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 --- io/router/clipboard.go | 14 +++----------- io/router/router.go | 4 ++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/io/router/clipboard.go b/io/router/clipboard.go index 70618b69..5f1623ca 100644 --- a/io/router/clipboard.go +++ b/io/router/clipboard.go @@ -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{}) } diff --git a/io/router/router.go b/io/router/router.go index 4a3df741..a09ecabc 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -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) } } }