mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 09:07:48 -04:00
Better runtime autoselection logic + more cleanup
This commit is contained in:
parent
28cbbaca61
commit
4115b997f8
@ -8,7 +8,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
|
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
|
||||||
import net.kdt.pojavlaunch.multirt.Runtime;
|
import net.kdt.pojavlaunch.multirt.Runtime;
|
||||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
|
||||||
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
|
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
|
||||||
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
|
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
|
||||||
|
|
||||||
@ -59,10 +58,12 @@ public class JRE17Util {
|
|||||||
LauncherProfiles.update();
|
LauncherProfiles.update();
|
||||||
MinecraftProfile minecraftProfile = LauncherProfiles.getCurrentProfile();
|
MinecraftProfile minecraftProfile = LauncherProfiles.getCurrentProfile();
|
||||||
|
|
||||||
String selectedRuntime = Tools.pickRuntime(minecraftProfile);
|
String selectedRuntime = Tools.getSelectedRuntime(minecraftProfile);
|
||||||
|
|
||||||
Runtime runtime = selectedRuntime != null ? MultiRTUtils.read(selectedRuntime) : MultiRTUtils.read(LauncherPreferences.PREF_DEFAULT_RUNTIME);
|
Runtime runtime = MultiRTUtils.read(selectedRuntime);
|
||||||
if (runtime.javaVersion >= versionInfo.javaVersion.majorVersion) return true;
|
if (runtime.javaVersion >= versionInfo.javaVersion.majorVersion) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String appropriateRuntime = MultiRTUtils.getNearestJreName(versionInfo.javaVersion.majorVersion);
|
String appropriateRuntime = MultiRTUtils.getNearestJreName(versionInfo.javaVersion.majorVersion);
|
||||||
if (appropriateRuntime != null) {
|
if (appropriateRuntime != null) {
|
||||||
|
@ -5,45 +5,61 @@ import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics;
|
|||||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_SUSTAINED_PERFORMANCE;
|
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_SUSTAINED_PERFORMANCE;
|
||||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_USE_ALTERNATE_SURFACE;
|
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_USE_ALTERNATE_SURFACE;
|
||||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_VIRTUAL_MOUSE_START;
|
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_VIRTUAL_MOUSE_START;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
|
import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
|
||||||
import static org.lwjgl.glfw.CallbackBridge.windowHeight;
|
import static org.lwjgl.glfw.CallbackBridge.windowHeight;
|
||||||
import static org.lwjgl.glfw.CallbackBridge.windowWidth;
|
import static org.lwjgl.glfw.CallbackBridge.windowWidth;
|
||||||
|
|
||||||
import android.app.*;
|
import android.app.Activity;
|
||||||
import android.content.*;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.*;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.provider.DocumentsContract;
|
import android.provider.DocumentsContract;
|
||||||
import android.util.*;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
import android.widget.*;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.drawerlayout.widget.*;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
|
|
||||||
import com.kdt.LoggerView;
|
import com.kdt.LoggerView;
|
||||||
|
|
||||||
import java.io.*;
|
import net.kdt.pojavlaunch.customcontrols.ControlButtonMenuListener;
|
||||||
import net.kdt.pojavlaunch.customcontrols.*;
|
import net.kdt.pojavlaunch.customcontrols.ControlData;
|
||||||
|
import net.kdt.pojavlaunch.customcontrols.ControlDrawerData;
|
||||||
|
import net.kdt.pojavlaunch.customcontrols.ControlLayout;
|
||||||
|
import net.kdt.pojavlaunch.customcontrols.CustomControls;
|
||||||
import net.kdt.pojavlaunch.customcontrols.keyboard.LwjglCharSender;
|
import net.kdt.pojavlaunch.customcontrols.keyboard.LwjglCharSender;
|
||||||
import net.kdt.pojavlaunch.customcontrols.keyboard.TouchCharInput;
|
import net.kdt.pojavlaunch.customcontrols.keyboard.TouchCharInput;
|
||||||
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
|
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||||
|
|
||||||
import net.kdt.pojavlaunch.prefs.*;
|
|
||||||
import net.kdt.pojavlaunch.services.GameService;
|
import net.kdt.pojavlaunch.services.GameService;
|
||||||
import net.kdt.pojavlaunch.utils.*;
|
import net.kdt.pojavlaunch.utils.JREUtils;
|
||||||
import net.kdt.pojavlaunch.value.*;
|
import net.kdt.pojavlaunch.utils.MCOptionUtils;
|
||||||
|
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||||
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
|
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
|
||||||
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
|
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
|
||||||
|
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.CallbackBridge;
|
||||||
import android.net.*;
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity implements ControlButtonMenuListener{
|
public class MainActivity extends BaseActivity implements ControlButtonMenuListener{
|
||||||
public static volatile ClipboardManager GLOBAL_CLIPBOARD;
|
public static volatile ClipboardManager GLOBAL_CLIPBOARD;
|
||||||
@ -61,8 +77,6 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
private GyroControl mGyroControl = null;
|
private GyroControl mGyroControl = null;
|
||||||
public static ControlLayout mControlLayout;
|
public static ControlLayout mControlLayout;
|
||||||
|
|
||||||
|
|
||||||
MinecraftAccount mProfile;
|
|
||||||
MinecraftProfile minecraftProfile;
|
MinecraftProfile minecraftProfile;
|
||||||
|
|
||||||
private ArrayAdapter<String> gameActionArrayAdapter;
|
private ArrayAdapter<String> gameActionArrayAdapter;
|
||||||
@ -70,13 +84,9 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
public ArrayAdapter<String> ingameControlsEditorArrayAdapter;
|
public ArrayAdapter<String> ingameControlsEditorArrayAdapter;
|
||||||
public AdapterView.OnItemClickListener ingameControlsEditorListener;
|
public AdapterView.OnItemClickListener ingameControlsEditorListener;
|
||||||
|
|
||||||
protected volatile String mVersionId;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
mProfile = PojavProfile.getCurrentProfileContent(this, null);
|
|
||||||
minecraftProfile = LauncherProfiles.getCurrentProfile();
|
minecraftProfile = LauncherProfiles.getCurrentProfile();
|
||||||
MCOptionUtils.load(Tools.getGameDirPath(minecraftProfile).getAbsolutePath());
|
MCOptionUtils.load(Tools.getGameDirPath(minecraftProfile).getAbsolutePath());
|
||||||
GameService.startService(this);
|
GameService.startService(this);
|
||||||
@ -138,8 +148,8 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
String version = getIntent().getStringExtra(INTENT_MINECRAFT_VERSION);
|
String version = getIntent().getStringExtra(INTENT_MINECRAFT_VERSION);
|
||||||
version = version == null ? minecraftProfile.lastVersionId : version;
|
version = version == null ? minecraftProfile.lastVersionId : version;
|
||||||
|
|
||||||
mVersionId = version;
|
JMinecraftVersionList.Version mVersionInfo = Tools.getVersionInfo(version);
|
||||||
isInputStackCall = Tools.getVersionInfo(mVersionId).arguments != null;
|
isInputStackCall = mVersionInfo.arguments != null;
|
||||||
CallbackBridge.nativeSetUseInputStackQueue(isInputStackCall);
|
CallbackBridge.nativeSetUseInputStackQueue(isInputStackCall);
|
||||||
|
|
||||||
Tools.getDisplayMetrics(this);
|
Tools.getDisplayMetrics(this);
|
||||||
@ -166,7 +176,7 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
drawerLayout.closeDrawers();
|
drawerLayout.closeDrawers();
|
||||||
|
|
||||||
|
|
||||||
|
final String finalVersion = version;
|
||||||
minecraftGLView.setSurfaceReadyListener(() -> {
|
minecraftGLView.setSurfaceReadyListener(() -> {
|
||||||
try {
|
try {
|
||||||
// Setup virtual mouse right before launching
|
// Setup virtual mouse right before launching
|
||||||
@ -174,7 +184,7 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
touchpad.post(() -> touchpad.switchState());
|
touchpad.post(() -> touchpad.switchState());
|
||||||
}
|
}
|
||||||
|
|
||||||
runCraft();
|
runCraft(finalVersion, mVersionInfo);
|
||||||
}catch (Throwable e){
|
}catch (Throwable e){
|
||||||
Tools.showError(getApplicationContext(), e, true);
|
Tools.showError(getApplicationContext(), e, true);
|
||||||
}
|
}
|
||||||
@ -301,27 +311,30 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
return Build.VERSION.SDK_INT >= 26;
|
return Build.VERSION.SDK_INT >= 26;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runCraft() throws Throwable {
|
private void runCraft(String versionId, JMinecraftVersionList.Version version) throws Throwable {
|
||||||
if(Tools.LOCAL_RENDERER == null) {
|
if(Tools.LOCAL_RENDERER == null) {
|
||||||
Tools.LOCAL_RENDERER = LauncherPreferences.PREF_RENDERER;
|
Tools.LOCAL_RENDERER = LauncherPreferences.PREF_RENDERER;
|
||||||
}
|
}
|
||||||
|
MinecraftAccount minecraftAccount = PojavProfile.getCurrentProfileContent(this, null);
|
||||||
Logger.getInstance().appendToLog("--------- beginning with launcher debug");
|
Logger.getInstance().appendToLog("--------- beginning with launcher debug");
|
||||||
printLauncherInfo();
|
printLauncherInfo(versionId);
|
||||||
if (Tools.LOCAL_RENDERER.equals("vulkan_zink")) {
|
if (Tools.LOCAL_RENDERER.equals("vulkan_zink")) {
|
||||||
checkVulkanZinkIsSupported();
|
checkVulkanZinkIsSupported();
|
||||||
}
|
}
|
||||||
JREUtils.redirectAndPrintJRELog();
|
JREUtils.redirectAndPrintJRELog();
|
||||||
LauncherProfiles.update();
|
LauncherProfiles.update();
|
||||||
Tools.launchMinecraft(this, mProfile, minecraftProfile, mVersionId);
|
int requiredJavaVersion = 8;
|
||||||
|
if(version.javaVersion != null) requiredJavaVersion = version.javaVersion.majorVersion;
|
||||||
|
Tools.launchMinecraft(this, minecraftAccount, minecraftProfile, versionId, requiredJavaVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printLauncherInfo() {
|
private void printLauncherInfo(String gameVersion) {
|
||||||
Logger logger = Logger.getInstance();
|
Logger logger = Logger.getInstance();
|
||||||
logger.appendToLog("Info: Launcher version: " + BuildConfig.VERSION_NAME);
|
logger.appendToLog("Info: Launcher version: " + BuildConfig.VERSION_NAME);
|
||||||
logger.appendToLog("Info: Architecture: " + Architecture.archAsString(Tools.DEVICE_ARCHITECTURE));
|
logger.appendToLog("Info: Architecture: " + Architecture.archAsString(Tools.DEVICE_ARCHITECTURE));
|
||||||
logger.appendToLog("Info: Device model: " + Build.MANUFACTURER + " " +Build.MODEL);
|
logger.appendToLog("Info: Device model: " + Build.MANUFACTURER + " " +Build.MODEL);
|
||||||
logger.appendToLog("Info: API version: " + Build.VERSION.SDK_INT);
|
logger.appendToLog("Info: API version: " + Build.VERSION.SDK_INT);
|
||||||
logger.appendToLog("Info: Selected Minecraft version: " + mVersionId);
|
logger.appendToLog("Info: Selected Minecraft version: " + gameVersion);
|
||||||
logger.appendToLog("Info: Custom Java arguments: \"" + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS + "\"");
|
logger.appendToLog("Info: Custom Java arguments: \"" + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import android.app.ProgressDialog;
|
|||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@ -152,7 +151,7 @@ public final class Tools {
|
|||||||
|
|
||||||
|
|
||||||
public static void launchMinecraft(final Activity activity, MinecraftAccount minecraftAccount,
|
public static void launchMinecraft(final Activity activity, MinecraftAccount minecraftAccount,
|
||||||
MinecraftProfile minecraftProfile, String versionId) throws Throwable {
|
MinecraftProfile minecraftProfile, String versionId, int versionJavaRequirement) throws Throwable {
|
||||||
int freeDeviceMemory = getFreeDeviceMemory(activity);
|
int freeDeviceMemory = getFreeDeviceMemory(activity);
|
||||||
if(LauncherPreferences.PREF_RAM_ALLOCATION > freeDeviceMemory) {
|
if(LauncherPreferences.PREF_RAM_ALLOCATION > freeDeviceMemory) {
|
||||||
Object memoryErrorLock = new Object();
|
Object memoryErrorLock = new Object();
|
||||||
@ -167,7 +166,7 @@ public final class Tools {
|
|||||||
memoryErrorLock.wait();
|
memoryErrorLock.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Runtime runtime = MultiRTUtils.forceReread(Tools.pickRuntime(minecraftProfile));
|
Runtime runtime = MultiRTUtils.forceReread(Tools.pickRuntime(minecraftProfile, versionJavaRequirement));
|
||||||
JMinecraftVersionList.Version versionInfo = Tools.getVersionInfo(versionId);
|
JMinecraftVersionList.Version versionInfo = Tools.getVersionInfo(versionId);
|
||||||
LauncherProfiles.update();
|
LauncherProfiles.update();
|
||||||
File gamedir = Tools.getGameDirPath(minecraftProfile);
|
File gamedir = Tools.getGameDirPath(minecraftProfile);
|
||||||
@ -551,10 +550,10 @@ public final class Tools {
|
|||||||
|
|
||||||
Runnable runnable = () -> {
|
Runnable runnable = () -> {
|
||||||
final String errMsg = showMore ? printToString(e) : rolledMessage != null ? rolledMessage : e.getMessage();
|
final String errMsg = showMore ? printToString(e) : rolledMessage != null ? rolledMessage : e.getMessage();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder((Context) ctx)
|
AlertDialog.Builder builder = new AlertDialog.Builder(ctx)
|
||||||
.setTitle(titleId)
|
.setTitle(titleId)
|
||||||
.setMessage(errMsg)
|
.setMessage(errMsg)
|
||||||
.setPositiveButton(android.R.string.ok, (DialogInterface.OnClickListener) (p1, p2) -> {
|
.setPositiveButton(android.R.string.ok, (p1, p2) -> {
|
||||||
if(exitIfOk) {
|
if(exitIfOk) {
|
||||||
if (ctx instanceof MainActivity) {
|
if (ctx instanceof MainActivity) {
|
||||||
MainActivity.fullyExit();
|
MainActivity.fullyExit();
|
||||||
@ -563,8 +562,8 @@ public final class Tools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(showMore ? R.string.error_show_less : R.string.error_show_more, (DialogInterface.OnClickListener) (p1, p2) -> showError(ctx, titleId, rolledMessage, e, exitIfOk, !showMore))
|
.setNegativeButton(showMore ? R.string.error_show_less : R.string.error_show_more, (p1, p2) -> showError(ctx, titleId, rolledMessage, e, exitIfOk, !showMore))
|
||||||
.setNeutralButton(android.R.string.copy, (DialogInterface.OnClickListener) (p1, p2) -> {
|
.setNeutralButton(android.R.string.copy, (p1, p2) -> {
|
||||||
ClipboardManager mgr = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager mgr = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
mgr.setPrimaryClip(ClipData.newPlainText("error", Log.getStackTraceString(e)));
|
mgr.setPrimaryClip(ClipData.newPlainText("error", Log.getStackTraceString(e)));
|
||||||
if(exitIfOk) {
|
if(exitIfOk) {
|
||||||
@ -938,14 +937,34 @@ public final class Tools {
|
|||||||
public static boolean isValidString(String string) {
|
public static boolean isValidString(String string) {
|
||||||
return string != null && !string.isEmpty();
|
return string != null && !string.isEmpty();
|
||||||
}
|
}
|
||||||
public static String pickRuntime(MinecraftProfile minecraftProfile) {
|
|
||||||
|
public static String getRuntimeName(String prefixedName) {
|
||||||
|
if(prefixedName == null) return prefixedName;
|
||||||
|
if(!prefixedName.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) return null;
|
||||||
|
return prefixedName.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSelectedRuntime(MinecraftProfile minecraftProfile) {
|
||||||
String runtime = LauncherPreferences.PREF_DEFAULT_RUNTIME;
|
String runtime = LauncherPreferences.PREF_DEFAULT_RUNTIME;
|
||||||
if(minecraftProfile.javaDir != null && minecraftProfile.javaDir.startsWith(Tools.LAUNCHERPROFILES_RTPREFIX)) {
|
String profileRuntime = getRuntimeName(minecraftProfile.javaDir);
|
||||||
String runtimeName = minecraftProfile.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length());
|
if(profileRuntime != null) {
|
||||||
if(MultiRTUtils.forceReread(runtimeName).versionString != null) {
|
if(MultiRTUtils.forceReread(profileRuntime).versionString != null) {
|
||||||
runtime = runtimeName;
|
runtime = profileRuntime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return runtime;
|
return runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @NonNull String pickRuntime(MinecraftProfile minecraftProfile, int targetJavaVersion) {
|
||||||
|
String runtime = getSelectedRuntime(minecraftProfile);
|
||||||
|
String profileRuntime = getRuntimeName(minecraftProfile.javaDir);
|
||||||
|
Runtime pickedRuntime = MultiRTUtils.read(runtime);
|
||||||
|
if(runtime == null || pickedRuntime.javaVersion == 0 || pickedRuntime.javaVersion < targetJavaVersion) {
|
||||||
|
String preferredRuntime = MultiRTUtils.getNearestJreName(targetJavaVersion);
|
||||||
|
if(preferredRuntime == null) throw new RuntimeException("Failed to autopick runtime!");
|
||||||
|
if(profileRuntime != null) minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+preferredRuntime;
|
||||||
|
runtime = preferredRuntime;
|
||||||
|
}
|
||||||
|
return runtime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user