Windows must be manually managed through the WaitFor function
Closes #5
This commit is contained in:
33
manager.go
Normal file
33
manager.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user