github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/generators/android_vanillajs_rest.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  
    14  	_ "github.com/pojntfx/hydrapp/hydrapp/pkg/fixes"
    15  	"github.com/pojntfx/hydrapp/hydrapp/pkg/utils"
    16  
    17  	backend "{{ .GoMod }}/pkg/backend"
    18  	frontend "{{ .GoMod }}/pkg/frontend"
    19  )
    20  
    21  //export Java_{{ .JNIExport }}_MainActivity_LaunchBackend
    22  func Java_{{ .JNIExport }}_MainActivity_LaunchBackend(env *C.JNIEnv, activity C.jobject) C.jstring {
    23  	if err := utils.PolyfillEnvironment(C.GoString(C.get_c_string(env, filesDir))); err != nil {
    24  		log.Fatalln("could not polyfill environment:", err)
    25  	}
    26  	
    27  	backendURL, _, err := backend.StartServer(context.Background(), "", false)
    28  	if err != nil {
    29  		log.Fatalln("could not start backend:", err)
    30  	}
    31  
    32  	log.Println("Backend URL:", backendURL)
    33  
    34  	frontendURL, _, err := frontend.StartServer(context.Background(), "", backendURL, false)
    35  	if err != nil {
    36  		log.Fatalln("could not start frontend:", err)
    37  	}
    38  
    39  	log.Println("Frontend URL:", frontendURL)
    40  
    41  	return C.get_java_string(env, C.CString(frontendURL))
    42  }
    43  
    44  func main() {}