execute jar with custom args

This commit is contained in:
ShirosakiMio 2024-01-13 13:54:11 +08:00
parent c4e7b72af8
commit e3aad8b692
5 changed files with 43 additions and 11 deletions

View File

@ -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);
}
};

View File

@ -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);

View File

@ -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<String> rawCommandLine = command.asList();

View File

@ -870,4 +870,6 @@
<string name="world_reveal">打开文件夹</string>
<string name="world_show_all">显示全部</string>
<string name="world_time">yyyy 年 MM 月 dd 日 HH:mm:ss</string>
<string name="dialog_custom_args">使用自定义参数执行</string>
</resources>

View File

@ -906,4 +906,6 @@
<string name="world_reveal">Reveal in Explorer</string>
<string name="world_show_all">Show All</string>
<string name="world_time">EEE, MMM d, yyyy HH:mm:ss</string>
<string name="dialog_custom_args">Execute with custom args</string>
</resources>