Skip to content

Commit

Permalink
windows: improve event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hattya committed Aug 21, 2024
1 parent bb24fa2 commit b1b5eec
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions windows/notify_windows.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// go.notify/windows :: notify_windows.go
//
// Copyright (c) 2017-2022 Akinori Hattori <hattya@gmail.com>
// Copyright (c) 2017-2024 Akinori Hattori <hattya@gmail.com>
//
// SPDX-License-Identifier: MIT
//
Expand Down Expand Up @@ -286,6 +286,7 @@ func (ni *NotifyIcon) event() {

var balloon chan BalloonEvent
var menu chan MenuEvent
var balloonIdx, menuIdx int
balloonBuf := make([]BalloonEvent, 1)
menuBuf := make([]MenuEvent, 1)

Expand All @@ -296,27 +297,31 @@ func (ni *NotifyIcon) event() {
case BalloonEvent:
if balloon == nil {
balloon = ni.Balloon
balloonBuf = balloonBuf[1:]
balloonIdx = 1
}
balloonBuf = append(balloonBuf, ev)
case MenuEvent:
if menu == nil {
menu = ni.Menu
menuBuf = menuBuf[1:]
menuIdx = 1
}
menuBuf = append(menuBuf, ev)
}
case balloon <- balloonBuf[0]:
if len(balloonBuf) == 1 {
case balloon <- balloonBuf[balloonIdx]:
if balloonIdx == len(balloonBuf)-1 {
balloon = nil
balloonIdx = 0
balloonBuf = balloonBuf[:1]
} else {
balloonBuf = balloonBuf[1:]
balloonIdx++
}
case menu <- menuBuf[0]:
if len(menuBuf) == 1 {
case menu <- menuBuf[menuIdx]:
if menuIdx == len(menuBuf)-1 {
menu = nil
menuIdx = 0
menuBuf = menuBuf[:1]
} else {
menuBuf = menuBuf[1:]
menuIdx++
}
case <-ni.done:
return
Expand Down

0 comments on commit b1b5eec

Please sign in to comment.