mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
ui/app: call main from Android and iOS
Android can only run c-shared libraries which means that every Gio program must create its window and event loop from an init function. The same applies to iOS but for a more benign reason: the gio tool builds programs in c-archive mode for iOS and links the binary with a Objective-C driver. Allow Gio programs to run off its main function by linking to and invoking main even from Android libraries and iOS ditto. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+13
-2
@@ -76,6 +76,19 @@ func jniGetStaticMethodID(env *C.JNIEnv, class C.jclass, method, sig string) C.j
|
||||
return C.gio_jni_GetStaticMethodID(env, class, m, s)
|
||||
}
|
||||
|
||||
//export runGoMain
|
||||
func runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyteArray) {
|
||||
dirBytes := C.gio_jni_GetByteArrayElements(env, jdataDir)
|
||||
if dirBytes == nil {
|
||||
panic("runGoMain: GetByteArrayElements failed")
|
||||
}
|
||||
n := C.gio_jni_GetArrayLength(env, jdataDir)
|
||||
dataDir := C.GoStringN((*C.char)(unsafe.Pointer(dirBytes)), n)
|
||||
setDataDir(dataDir)
|
||||
C.gio_jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
||||
runMain()
|
||||
}
|
||||
|
||||
//export setJVM
|
||||
func setJVM(vm *C.JavaVM) {
|
||||
theJVM = vm
|
||||
@@ -407,8 +420,6 @@ func (w *window) showTextInput(show bool) {
|
||||
}
|
||||
|
||||
func Main() {
|
||||
// Android runs in c-shared mode where main is never reached.
|
||||
panic("call to Main from outside main")
|
||||
}
|
||||
|
||||
func createWindow(window *Window, opts *WindowOptions) error {
|
||||
|
||||
Reference in New Issue
Block a user