mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +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 (
|
import (
|
||||||
"gioui.org/io/event"
|
"gioui.org/io/event"
|
||||||
|
|
||||||
"gioui.org/internal/opconst"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type clipboardQueue struct {
|
type clipboardQueue struct {
|
||||||
@@ -29,7 +27,7 @@ func (q *clipboardQueue) WriteClipboard() (string, bool) {
|
|||||||
// ReadClipboard reports if any new handler is waiting
|
// ReadClipboard reports if any new handler is waiting
|
||||||
// to read the clipboard.
|
// to read the clipboard.
|
||||||
func (q *clipboardQueue) ReadClipboard() bool {
|
func (q *clipboardQueue) ReadClipboard() bool {
|
||||||
if len(q.receivers) <= 0 || q.requested {
|
if len(q.receivers) == 0 || q.requested {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
q.requested = true
|
q.requested = true
|
||||||
@@ -43,17 +41,11 @@ func (q *clipboardQueue) Push(e event.Event, events *handlerEvents) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *clipboardQueue) ProcessWriteClipboard(d []byte, refs []interface{}) {
|
func (q *clipboardQueue) ProcessWriteClipboard(refs []interface{}) {
|
||||||
if opconst.OpType(d[0]) != opconst.TypeClipboardWrite {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
q.text = refs[0].(*string)
|
q.text = refs[0].(*string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *clipboardQueue) ProcessReadClipboard(d []byte, refs []interface{}) {
|
func (q *clipboardQueue) ProcessReadClipboard(refs []interface{}) {
|
||||||
if opconst.OpType(d[0]) != opconst.TypeClipboardRead {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
if q.receivers == nil {
|
if q.receivers == nil {
|
||||||
q.receivers = make(map[event.Tag]struct{})
|
q.receivers = make(map[event.Tag]struct{})
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -140,9 +140,9 @@ func (q *Router) collect() {
|
|||||||
}
|
}
|
||||||
q.profHandlers[op.Tag] = struct{}{}
|
q.profHandlers[op.Tag] = struct{}{}
|
||||||
case opconst.TypeClipboardRead:
|
case opconst.TypeClipboardRead:
|
||||||
q.cqueue.ProcessReadClipboard(encOp.Data, encOp.Refs)
|
q.cqueue.ProcessReadClipboard(encOp.Refs)
|
||||||
case opconst.TypeClipboardWrite:
|
case opconst.TypeClipboardWrite:
|
||||||
q.cqueue.ProcessWriteClipboard(encOp.Data, encOp.Refs)
|
q.cqueue.ProcessWriteClipboard(encOp.Refs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user