forked from joejulian/gio
app: [Android] delete redundant dataDirChan
since dataDir() must call after main(), it's redundant to use channel to send path Signed-off-by: CoyAce <AkeyCoy@gmail.com> Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-2
@@ -130,8 +130,7 @@ func NewContext(ops *op.Ops, e FrameEvent) layout.Context {
|
|||||||
// On iOS NSDocumentDirectory is queried.
|
// On iOS NSDocumentDirectory is queried.
|
||||||
// For Android Context.getFilesDir is used.
|
// For Android Context.getFilesDir is used.
|
||||||
//
|
//
|
||||||
// Note that on Android, DataDir blocks until main is called.
|
// BUG: On Android, DataDir panics if called before main.
|
||||||
// Don't call it from init functions or global variable initializers.
|
|
||||||
func DataDir() (string, error) {
|
func DataDir() (string, error) {
|
||||||
return dataDir()
|
return dataDir()
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-8
@@ -218,8 +218,6 @@ type AndroidViewEvent struct {
|
|||||||
|
|
||||||
type jvalue uint64 // The largest JNI type fits in 64 bits.
|
type jvalue uint64 // The largest JNI type fits in 64 bits.
|
||||||
|
|
||||||
var dataDirChan = make(chan string, 1)
|
|
||||||
|
|
||||||
var android struct {
|
var android struct {
|
||||||
// mu protects all fields of this structure. However, once a
|
// mu protects all fields of this structure. However, once a
|
||||||
// non-nil jvm is returned from javaVM, all the other fields may
|
// non-nil jvm is returned from javaVM, all the other fields may
|
||||||
@@ -295,8 +293,7 @@ var mainWindow = newWindowRendezvous()
|
|||||||
var mainFuncs = make(chan func(env *C.JNIEnv), 1)
|
var mainFuncs = make(chan func(env *C.JNIEnv), 1)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dataDirOnce sync.Once
|
dataPath string
|
||||||
dataPath string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -343,9 +340,9 @@ func (w *window) NewContext() (context, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataDir() (string, error) {
|
func dataDir() (string, error) {
|
||||||
dataDirOnce.Do(func() {
|
if dataPath == "" {
|
||||||
dataPath = <-dataDirChan
|
panic("DataDir isn't valid before main")
|
||||||
})
|
}
|
||||||
return dataPath, nil
|
return dataPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +395,7 @@ func Java_org_gioui_Gio_runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyt
|
|||||||
os.Setenv("HOME", dataDir)
|
os.Setenv("HOME", dataDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataDirChan <- dataDir
|
dataPath = dataDir
|
||||||
C.jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
C.jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
||||||
|
|
||||||
runMain()
|
runMain()
|
||||||
|
|||||||
Reference in New Issue
Block a user