From e3aad8b69245d3aac253303d691c9e809e81aba1 Mon Sep 17 00:00:00 2001 From: ShirosakiMio <852468399@qq.com> Date: Sat, 13 Jan 2024 13:54:11 +0800 Subject: [PATCH] execute jar with custom args --- .../tungsten/fcl/activity/MainActivity.java | 21 +++++++++++++++++-- .../tungsten/fcl/game/JarExecutorHelper.java | 8 +++++-- .../fcl/game/JarExecutorLauncher.java | 21 ++++++++++++------- FCL/src/main/res/values-zh/strings.xml | 2 ++ FCL/src/main/res/values/strings.xml | 2 ++ 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/FCL/src/main/java/com/tungsten/fcl/activity/MainActivity.java b/FCL/src/main/java/com/tungsten/fcl/activity/MainActivity.java index 45b360d8..125b5a0a 100644 --- a/FCL/src/main/java/com/tungsten/fcl/activity/MainActivity.java +++ b/FCL/src/main/java/com/tungsten/fcl/activity/MainActivity.java @@ -12,6 +12,7 @@ import android.os.Bundle; import android.view.View; import android.widget.ScrollView; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.LinearLayoutCompat; import androidx.constraintlayout.widget.ConstraintLayout; @@ -47,6 +48,7 @@ import com.tungsten.fcllibrary.component.FCLActivity; import com.tungsten.fcllibrary.component.theme.ThemeEngine; import com.tungsten.fcllibrary.component.view.FCLButton; import com.tungsten.fcllibrary.component.view.FCLDynamicIsland; +import com.tungsten.fcllibrary.component.view.FCLEditText; import com.tungsten.fcllibrary.component.view.FCLImageView; import com.tungsten.fcllibrary.component.view.FCLMenuView; import com.tungsten.fcllibrary.component.view.FCLTextView; @@ -172,6 +174,22 @@ public class MainActivity extends FCLActivity implements FCLMenuView.OnSelectLis account.setOnClickListener(this); version.setOnClickListener(this); executeJar.setOnClickListener(this); + executeJar.setOnLongClickListener(V -> { + FCLEditText editText = new FCLEditText(MainActivity.this); + editText.setHint("-jar xxx"); + editText.setLines(1); + editText.setMaxLines(1); + AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) + .setTitle(R.string.dialog_custom_args) + .setView(editText) + .setPositiveButton(com.tungsten.fcllibrary.R.string.dialog_positive, (dialog1, which) -> { + JarExecutorHelper.exec(MainActivity.this, null, 8, editText.getText().toString()); + }) + .setNegativeButton(com.tungsten.fcllibrary.R.string.dialog_negative, null) + .create(); + dialog.show(); + return true; + }); launch.setOnClickListener(this); launch.setOnLongClickListener(view -> { startActivity(new Intent(MainActivity.this, ShellActivity.class)); @@ -211,8 +229,7 @@ public class MainActivity extends FCLActivity implements FCLMenuView.OnSelectLis i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addCategory(Intent.CATEGORY_HOME); startActivity(i); - } - else { + } else { home.setSelected(true); } }; diff --git a/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorHelper.java b/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorHelper.java index 57179a69..36132aae 100644 --- a/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorHelper.java +++ b/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorHelper.java @@ -51,10 +51,14 @@ public class JarExecutorHelper { private static void launchJarExecutor(Context context, File file) { int version = getJavaVersion(file); int javaVersion = getNearestJavaVersion(version); + exec(context, file, javaVersion, null); + } + + public static void exec(Context context, File file, int javaVersion, String args) { JarExecutorLauncher launcher = new JarExecutorLauncher(context); - launcher.setInfo(file.getAbsolutePath(), javaVersion); + launcher.setInfo(file == null ? null : file.getAbsolutePath(), javaVersion); try { - FCLBridge fclBridge = launcher.launch(); + FCLBridge fclBridge = launcher.launch(args); Intent intent = new Intent(context, JVMActivity.class); fclBridge.setScaleFactor(1f); fclBridge.setController(null); diff --git a/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorLauncher.java b/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorLauncher.java index e7862a21..f604cb07 100644 --- a/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorLauncher.java +++ b/FCL/src/main/java/com/tungsten/fcl/game/JarExecutorLauncher.java @@ -14,6 +14,7 @@ import com.tungsten.fclcore.util.platform.MemoryUtils; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -31,7 +32,7 @@ public class JarExecutorLauncher extends Launcher { this.javaVersion = javaVersion; } - private CommandBuilder generateCommandLine() { + private CommandBuilder generateCommandLine(String args) { CommandBuilder res = new CommandBuilder(); getCacioJavaArgs(res, javaVersion == 8); @@ -43,9 +44,14 @@ public class JarExecutorLauncher extends Launcher { res.addDefault("-Djava.io.tmpdir=", FCLPath.CACHE_DIR); res.addDefault("-Dorg.lwjgl.opengl.libname=", "${gl_lib_name}"); - res.add("-jar"); - res.add(destJarPath); - + if (args != null) { + for (String s : Arrays.asList(args.split(" "))) { + res.add(s); + } + } else { + res.add("-jar"); + res.add(destJarPath); + } return res; } @@ -96,10 +102,11 @@ public class JarExecutorLauncher extends Launcher { @Override public FCLBridge launch() throws IOException, InterruptedException { - if (destJarPath == null) - throw new RuntimeException("ExecutorLauncher not initialized!"); + return null; + } - final CommandBuilder command = generateCommandLine(); + public FCLBridge launch(String args) throws IOException, InterruptedException { + final CommandBuilder command = generateCommandLine(args); List rawCommandLine = command.asList(); diff --git a/FCL/src/main/res/values-zh/strings.xml b/FCL/src/main/res/values-zh/strings.xml index 4c69e37c..7b49625e 100644 --- a/FCL/src/main/res/values-zh/strings.xml +++ b/FCL/src/main/res/values-zh/strings.xml @@ -870,4 +870,6 @@ 打开文件夹 显示全部 yyyy 年 MM 月 dd 日 HH:mm:ss + + 使用自定义参数执行 \ No newline at end of file diff --git a/FCL/src/main/res/values/strings.xml b/FCL/src/main/res/values/strings.xml index 104a212f..58925de3 100644 --- a/FCL/src/main/res/values/strings.xml +++ b/FCL/src/main/res/values/strings.xml @@ -906,4 +906,6 @@ Reveal in Explorer Show All EEE, MMM d, yyyy HH:mm:ss + + Execute with custom args \ No newline at end of file