Migrated uitask_windows.go to the new API.

This commit is contained in:
Pietro Gagliardi 2014-06-28 10:49:23 -04:00
parent f7438c0e10
commit 98e701cd3b
2 changed files with 27 additions and 24 deletions

View File

@ -24,6 +24,7 @@ func Go() error {
Ready <- struct{}{} Ready <- struct{}{}
close(Ready) close(Ready)
ui() ui()
return nil
} }
// Ready is pulsed when Go() is ready to begin accepting requests to the safe methods. // Ready is pulsed when Go() is ready to begin accepting requests to the safe methods.

View File

@ -46,10 +46,7 @@ var (
_postMessage = user32.NewProc("PostMessageW") _postMessage = user32.NewProc("PostMessageW")
) )
func ui(main func()) error { func uiinit() error {
runtime.LockOSThread()
uitask = make(chan interface{})
err := doWindowsInit() err := doWindowsInit()
if err != nil { if err != nil {
return fmt.Errorf("error doing general Windows initialization: %v", err) return fmt.Errorf("error doing general Windows initialization: %v", err)
@ -60,8 +57,16 @@ func ui(main func()) error {
return fmt.Errorf("error making invisible window for handling events: %v", err) return fmt.Errorf("error making invisible window for handling events: %v", err)
} }
// do this only on success just to be safe
uitask = make(chan interface{})
return nil
}
func ui() {
go func() { go func() {
for m := range uitask { for {
select {
case m := <-uitask:
r1, _, err := _postMessage.Call( r1, _, err := _postMessage.Call(
uintptr(hwnd), uintptr(hwnd),
msgRequested, msgRequested,
@ -70,11 +75,7 @@ func ui(main func()) error {
if r1 == 0 { // failure if r1 == 0 { // failure
panic("error sending message to message loop to call function: " + err.Error()) panic("error sending message to message loop to call function: " + err.Error())
} }
} case <-Stop:
}()
go func() {
main()
r1, _, err := _postMessage.Call( r1, _, err := _postMessage.Call(
uintptr(hwnd), uintptr(hwnd),
msgQuit, msgQuit,
@ -83,10 +84,11 @@ func ui(main func()) error {
if r1 == 0 { // failure if r1 == 0 { // failure
panic("error sending quit message to message loop: " + err.Error()) panic("error sending quit message to message loop: " + err.Error())
} }
}
}
}() }()
msgloop() msgloop()
return nil
} }
var ( var (