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:
CoyAce
2026-01-07 20:02:19 +08:00
committed by Elias Naur
parent e38f80adc6
commit 99647591f6
2 changed files with 6 additions and 10 deletions
+1 -2
View File
@@ -130,8 +130,7 @@ func NewContext(ops *op.Ops, e FrameEvent) layout.Context {
// On iOS NSDocumentDirectory is queried.
// For Android Context.getFilesDir is used.
//
// Note that on Android, DataDir blocks until main is called.
// Don't call it from init functions or global variable initializers.
// BUG: On Android, DataDir panics if called before main.
func DataDir() (string, error) {
return dataDir()
}
+4 -7
View File
@@ -218,8 +218,6 @@ type AndroidViewEvent struct {
type jvalue uint64 // The largest JNI type fits in 64 bits.
var dataDirChan = make(chan string, 1)
var android struct {
// mu protects all fields of this structure. However, once a
// non-nil jvm is returned from javaVM, all the other fields may
@@ -295,7 +293,6 @@ var mainWindow = newWindowRendezvous()
var mainFuncs = make(chan func(env *C.JNIEnv), 1)
var (
dataDirOnce sync.Once
dataPath string
)
@@ -343,9 +340,9 @@ func (w *window) NewContext() (context, error) {
}
func dataDir() (string, error) {
dataDirOnce.Do(func() {
dataPath = <-dataDirChan
})
if dataPath == "" {
panic("DataDir isn't valid before main")
}
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)
}
dataDirChan <- dataDir
dataPath = dataDir
C.jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
runMain()