mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app: [Android] replace PlatformHandle with JavaVM, AppContext methods
Clearer and fewer types. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+8
-4
@@ -4,11 +4,15 @@ import (
|
||||
"gioui.org/app/internal/window"
|
||||
)
|
||||
|
||||
type Handle window.Handle
|
||||
// JavaVM returns the global JNI JavaVM.
|
||||
func JavaVM() uintptr {
|
||||
return window.JavaVM()
|
||||
}
|
||||
|
||||
// PlatformHandle returns the Android platform-specific Handle.
|
||||
func PlatformHandle() *Handle {
|
||||
return (*Handle)(window.PlatformHandle)
|
||||
// AppContext returns the global Application context as a JNI
|
||||
// jobject.
|
||||
func AppContext() uintptr {
|
||||
return window.AppContext()
|
||||
}
|
||||
|
||||
// androidDriver is an interface that allows the Window's run method
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package window
|
||||
|
||||
var PlatformHandle *Handle
|
||||
|
||||
type Handle struct {
|
||||
// JVM is the JNI *JVM pointer.
|
||||
JVM uintptr
|
||||
// Context is a global reference to the application's
|
||||
// android.content.Context instance.
|
||||
Context uintptr
|
||||
}
|
||||
@@ -61,6 +61,8 @@ var dataDirChan = make(chan string, 1)
|
||||
|
||||
var theJVM *C.JavaVM
|
||||
|
||||
var appContext C.jobject
|
||||
|
||||
var views = make(map[C.jlong]*window)
|
||||
|
||||
var mainWindow = newWindowRendezvous()
|
||||
@@ -91,15 +93,19 @@ func runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyteArray, context C.j
|
||||
dataDir := C.GoStringN((*C.char)(unsafe.Pointer(dirBytes)), n)
|
||||
dataDirChan <- dataDir
|
||||
C.gio_jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
||||
context = C.gio_jni_NewGlobalRef(env, context)
|
||||
appContext = C.gio_jni_NewGlobalRef(env, context)
|
||||
|
||||
PlatformHandle = &Handle{
|
||||
JVM: uintptr(unsafe.Pointer(theJVM)),
|
||||
Context: uintptr(context),
|
||||
}
|
||||
runMain()
|
||||
}
|
||||
|
||||
func JavaVM() uintptr {
|
||||
return uintptr(unsafe.Pointer(theJVM))
|
||||
}
|
||||
|
||||
func AppContext() uintptr {
|
||||
return uintptr(appContext)
|
||||
}
|
||||
|
||||
func GetDataDir() string {
|
||||
return <-dataDirChan
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user