mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
+3
-11
@@ -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
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user