diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java index 1f2e8471..6a2d7e51 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java @@ -13,34 +13,7 @@ import net.kdt.pojavlaunch.prefs.*; import net.kdt.pojavlaunch.utils.*; import net.kdt.pojavlaunch.value.*; -public class PLaunchApp /* extends UIApplicationDelegateAdapter */ { -/* - @Override - public boolean didFinishLaunching(UIApplication application, - UIApplicationLaunchOptions launchOptions) { - File f = new File(Tools.DIR_HOME_JRE); - if (f.exists()) { - Thread launchThread = new Thread() { - @Override - public void run() { - Application.launch(PLaunchJFXApp.class); - } - }; - launchThread.setDaemon(true); - launchThread.start(); - } else { - WindowAlertController alertController = new WindowAlertController("Error", "OpenJDK is not installed. Please install before enter launcher.", UIAlertControllerStyle.Alert); - alertController.addAction(new UIAlertAction("OK", - UIAlertActionStyle.Default, (action) -> { - alertController.dismissViewController(true, null); - } - )); - alertController.show(); - } - - return true; - } -*/ +public class PLaunchApp { public static void main(String[] args) { /* Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @@ -75,30 +48,13 @@ public class PLaunchApp /* extends UIApplicationDelegateAdapter */ { throw new RuntimeException(th); } */ - - System.out.println("Input args: " + Arrays.toString(args)); System.out.println("We are on java now! Starting UI..."); org.lwjgl.glfw.CallbackBridge.nativeLaunchUI(args); LauncherPreferences.loadPreferences(); - - System.setProperty("java.library.path", Tools.DIR_DATA + "/Frameworks"); - - System.setProperty("javafx.verbose", "true"); - System.setProperty("javafx.platform", "ios"); - System.setProperty("glass.platform", "ios"); - System.setProperty("jfxmedia.platforms", "IOSPlatform"); - System.setProperty("com.sun.javafx.isEmbedded", "true"); - - System.setProperty("prism.verbose", "true"); - System.setProperty("prism.allowhidpi", "true"); - System.setProperty("prism.mintexturesize", "16"); - System.setProperty("prism.static.libraries", "true"); - System.setProperty("prism.useNativeIIO", "false"); - - CallbackBridge.windowWidth = (int) 1280; // bounds.getWidth(); - CallbackBridge.windowHeight = (int) 720; // bounds.getHeight(); - + } + + public static void launchMinecraft() { JREUtils.saveGLContext(); // Start Minecraft there! diff --git a/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java b/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java index 3f5ae56d..6694b0d5 100644 --- a/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java +++ b/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java @@ -146,6 +146,12 @@ public class CallbackBridge { } return currMods; } + + public static void callback_AppDelegate_didFinishLaunching(int width, int height) { + windowWidth = width; + windowHeight = height; + net.kdt.pojavlaunch.PLaunchApp.launchMinecraft(); + } public static native boolean nativeAttachThreadToOther(boolean isAndroid, boolean isUsePushPoll); /* diff --git a/Natives/AppDelegate.m b/Natives/AppDelegate.m index 65879cf2..fec5ac11 100644 --- a/Natives/AppDelegate.m +++ b/Natives/AppDelegate.m @@ -4,8 +4,12 @@ #import "AppDelegate.h" #import "JavaLauncher.h" + #import +#import "utils.h" +#import + @interface AppDelegate () @end @@ -16,7 +20,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"Hello from app launch!"); - // TODO callback + int width_c = (int) roundf([[UIScreen mainScreen] bounds].size.width); + int height_c = (int) roundf([[UIScreen mainScreen] bounds].size.height); + callback_AppDelegate_didFinishLaunching(width_c, height_c); return YES; } diff --git a/Natives/input_bridge_v3.c b/Natives/input_bridge_v3.c index 94cb99be..9ebe6b45 100644 --- a/Natives/input_bridge_v3.c +++ b/Natives/input_bridge_v3.c @@ -172,7 +172,20 @@ void closeGLFWWindow() { exit(-1); } +void callback_AppDelegate_didFinishLaunching(int width, int height) { + jclass clazz = (*runtimeJNIEnvPtr_JRE)->FindClass(runtimeJNIEnvPtr_JRE, "org/lwjgl/glfw/CallbackBridge"); + jmethodID method = (*runtimeJNIEnvPtr_JRE)->GetStaticMethodID(runtimeJNIEnvPtr_JRE, *clazz, "callback_AppDelegate_didFinishLaunching", "(II)V"); + (*runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod( + runtimeJNIEnvPtr_JRE, + clazz, method, + width, height + ); +} + JNIEXPORT jint JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeLaunchUI(JNIEnv* env, jclass clazz, jobjectArray args) { + // Save the JNIEnv pointer for AppDelegate callback + runtimeJNIEnvPtr_JRE = env; + int argc = (*env)->GetArrayLength(env, args); char **argv = convert_to_char_array(env, args); return launchUI(argc, argv); diff --git a/Natives/utils.h b/Natives/utils.h index 8cb9f15b..a874f0e7 100644 --- a/Natives/utils.h +++ b/Natives/utils.h @@ -26,6 +26,7 @@ jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charArray); void closeGLFWWindow(); +void callback_AppDelegate_didFinishLaunching(int width, int height); #endif // _BINARY_UTILS_H_