34 lines
615 B
Go
34 lines
615 B
Go
|
package nasin
|
||
|
|
||
|
import "git.tebibyte.media/tomo/tomo"
|
||
|
import "git.tebibyte.media/tomo/tomo/event"
|
||
|
|
||
|
var manager struct {
|
||
|
count int
|
||
|
}
|
||
|
|
||
|
type funcCookie func ()
|
||
|
func (cookie funcCookie) Close () {
|
||
|
cookie()
|
||
|
}
|
||
|
|
||
|
// WaitFor ensures that the application will stay running while the given window
|
||
|
// is open.
|
||
|
func WaitFor (window tomo.Window) event.Cookie {
|
||
|
manager.count ++
|
||
|
|
||
|
isManaged := true
|
||
|
handleClose := func () {
|
||
|
if !isManaged { return }
|
||
|
isManaged = false
|
||
|
manager.count --
|
||
|
if manager.count < 1 {
|
||
|
tomo.Stop()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return event.MultiCookie (
|
||
|
window.OnClose(handleClose),
|
||
|
funcCookie(handleClose))
|
||
|
}
|