Migrated init.go to the new API. This should probably be renamed now.

This commit is contained in:
Pietro Gagliardi 2014-06-28 10:15:24 -04:00
parent 3fbf746682
commit f7438c0e10
1 changed files with 28 additions and 10 deletions

38
init.go
View File

@ -2,21 +2,39 @@
package ui package ui
// Go sets up the UI environment and runs main in a goroutine. import (
// If initialization fails, Go returns an error and main is not called. "runtime"
// Otherwise, Go does not return to its caller until main does, at which point it returns nil. )
// After it returns, you cannot call future ui functions/methods meaningfully.
// Go sets up the UI environment and pulses Ready.
// If initialization fails, Go returns an error and Ready is not pulsed.
// Otherwise, Go does not return to its caller until Stop is pulsed, at which point Go() will return nil.
// After Go() returns, you cannot call future ui functions/methods meaningfully.
// Pulsing Stop will cause Go() to return immediately; the programmer is responsible for cleaning up (for instance, hiding open Windows) beforehand.
// //
// It is not safe to call ui.Go() in a goroutine. It must be called directly from main(). // It is not safe to call ui.Go() in a goroutine. It must be called directly from main(). This means if your code calls other code-modal servers (such as http.ListenAndServe()), they must be run from goroutines. (This is due to limitations in various OSs, such as Mac OS X.)
// //
// This model is undesirable, but Cocoa limitations require it. // Go() does not process the command line for flags (that is, it does not call flag.Parse()), nor does package ui add any of the underlying toolkit's supported command-line flags.
//
// Go does not process the command line for flags (that is, it does not call flag.Parse()), nor does package ui add any of the underlying toolkit's supported command-line flags.
// If you must, and if the toolkit also has environment variable equivalents to these flags (for instance, GTK+), use those instead. // If you must, and if the toolkit also has environment variable equivalents to these flags (for instance, GTK+), use those instead.
func Go(main func()) error { func Go() error {
return ui(main) runtime.LockOSThread()
if err := uiinit(main); err != nil {
return err
}
Ready <- struct{}{}
close(Ready)
ui()
} }
// Ready is pulsed when Go() is ready to begin accepting requests to the safe methods.
// Go() will wait for something to receive on Ready, then Ready will be closed.
var Ready = make(chan struct{})
// Stop should be pulsed when you are ready for Go() to return.
// Pulsing Stop will cause Go() to return immediately; the programmer is responsible for cleaning up (for instance, hiding open Windows) beforehand.
// Do not pulse Stop more than once.
var Stop = make(chan struct{})
// This function is a simple helper functionn that basically pushes the effect of a function call for later. This allows the selected safe Window methods to be safe. // This function is a simple helper functionn that basically pushes the effect of a function call for later. This allows the selected safe Window methods to be safe.
// It's also currently used by the various dialog box functions on Windows to allow them to return instantly, rather than wait for the dialog box to finish (which both GTK+ and Mac OS X let you do). I consider this a race condition bug. TODO (also TODO document the /intended/ behavior) // It's also currently used by the various dialog box functions on Windows to allow them to return instantly, rather than wait for the dialog box to finish (which both GTK+ and Mac OS X let you do). I consider this a race condition bug. TODO (also TODO document the /intended/ behavior)
func touitask(f func()) { func touitask(f func()) {