github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/generators/android_react_panrpc.go.tpl (about)

     1  //go:build android
     2  // +build android
     3  
     4  package main
     5  
     6  /*
     7  #include "hydrapp_android.h"
     8  */
     9  import "C"
    10  import (
    11  	"context"
    12  	"log"
    13  	"time"
    14  
    15  	_ "github.com/pojntfx/hydrapp/hydrapp/pkg/fixes"
    16  	"github.com/pojntfx/hydrapp/hydrapp/pkg/utils"
    17  
    18  	backend "{{ .GoMod }}/pkg/backend"
    19  	frontend "{{ .GoMod }}/pkg/frontend"
    20  )
    21  
    22  //export Java_{{ .JNIExport }}_MainActivity_LaunchBackend
    23  func Java_{{ .JNIExport }}_MainActivity_LaunchBackend(env *C.JNIEnv, activity C.jobject, filesDir C.jstring) C.jstring {
    24  	if err := utils.PolyfillEnvironment(C.GoString(C.get_c_string(env, filesDir))); err != nil {
    25  		log.Fatalln("could not polyfill environment:", err)
    26  	}
    27  	
    28  	backendURL, _, err := backend.StartServer(context.Background(), "", time.Second*10, true)
    29  	if err != nil {
    30  		log.Fatalln("could not start backend:", err)
    31  	}
    32  
    33  	log.Println("Backend URL:", backendURL)
    34  
    35  	frontendURL, _, err := frontend.StartServer(context.Background(), "", backendURL, true)
    36  	if err != nil {
    37  		log.Fatalln("could not start frontend:", err)
    38  	}
    39  
    40  	log.Println("Frontend URL:", frontendURL)
    41  
    42  	return C.get_java_string(env, C.CString(frontendURL))
    43  }
    44  
    45  func main() {}