mirror of
https://github.com/fankes/termux-app.git
synced 2025-10-22 11:49:21 +08:00
Added|Changed!: Rename SESSION_NAME
and SESSION_CREATE_MODE
to SHELL_NAME
and SHELL_CREATE_MODE
and add support for ShellCreateMode
to AppShells
Renamed extras `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_NAME` to `*.EXTRA_SHELL_NAME`, `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_NAME` to `*.EXTRA_SHELL_NAME`, `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE` to `*.EXTRA_SHELL_CREATE_MODE` and `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_CREATE_MODE` to `*.EXTRA_SHELL_CREATE_MODE`.
Renamed `enum` class `SessionCreateMode` to `ShellCreateMode`, `sessionName` field to `shellName`, `sessionCreateMode` to `shellCreateMode` in `ExecutionCommand`.
The `TermuxService` `AppShells`/`TermuxTasks` will now consider `ShellCreateMode` as well before starting tasks as done for `TermuxSessions` via 5794ab9a
New task command to not create new foreground session and switch to existing session if one already exits with `shellName` is
```
am startservice --user 0 -n com.termux/com.termux.app.RunCommandService \
-a com.termux.RUN_COMMAND \
--es com.termux.RUN_COMMAND_PATH '/data/data/com.termux/files/usr/bin/bash' \
--es com.termux.RUN_COMMAND_SHELL_CREATE_MODE 'no-shell-with-name' \
--es com.termux.RUN_COMMAND_SHELL_NAME "custom-name"
```
New task command to not create new background task if one already exits with `shellName` is
```
am startservice --user 0 -n com.termux/com.termux.app.RunCommandService \
-a com.termux.RUN_COMMAND \
--es com.termux.RUN_COMMAND_PATH '/data/data/com.termux/files/usr/bin/top' \
--esa com.termux.RUN_COMMAND_ARGUMENTS '-n,5' \
--es com.termux.RUN_COMMAND_SHELL_CREATE_MODE 'no-shell-with-name' \
--es com.termux.RUN_COMMAND_SHELL_NAME "custom-name" \
--es com.termux.RUN_COMMAND_RUNNER "app-shell"
```
This commit is contained in:
@@ -105,17 +105,17 @@ public class ExecutionCommand {
|
||||
|
||||
}
|
||||
|
||||
public enum SessionCreateMode {
|
||||
public enum ShellCreateMode {
|
||||
|
||||
/** Always create {@link TerminalSession}. */
|
||||
ALWAYS("always"),
|
||||
|
||||
/** Create session only if no session with {@link #sessionName} found. */
|
||||
NO_SESSION_WITH_NAME("no-session-with-name");
|
||||
/** Create shell only if no shell with {@link #shellName} found. */
|
||||
NO_SHELL_WITH_NAME("no-shell-with-name");
|
||||
|
||||
private final String mode;
|
||||
|
||||
SessionCreateMode(final String mode) {
|
||||
ShellCreateMode(final String mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@@ -127,10 +127,10 @@ public class ExecutionCommand {
|
||||
return sessionCreateMode != null && sessionCreateMode.equals(this.mode);
|
||||
}
|
||||
|
||||
/** Get {@link SessionCreateMode} for {@code mode} if found, otherwise {@code null}. */
|
||||
/** Get {@link ShellCreateMode} for {@code mode} if found, otherwise {@code null}. */
|
||||
@Nullable
|
||||
public static SessionCreateMode modeOf(String mode) {
|
||||
for (SessionCreateMode v : SessionCreateMode.values()) {
|
||||
public static ShellCreateMode modeOf(String mode) {
|
||||
for (ShellCreateMode v : ShellCreateMode.values()) {
|
||||
if (v.mode.equals(mode)) {
|
||||
return v;
|
||||
}
|
||||
@@ -187,11 +187,12 @@ public class ExecutionCommand {
|
||||
/** The session action of {@link Runner#TERMINAL_SESSION} commands. */
|
||||
public String sessionAction;
|
||||
|
||||
/** The session name of {@link Runner#TERMINAL_SESSION} commands. */
|
||||
public String sessionName;
|
||||
|
||||
/** The {@link SessionCreateMode} of session for {@link Runner#TERMINAL_SESSION} commands. */
|
||||
public String sessionCreateMode;
|
||||
/** The shell name of commands. */
|
||||
public String shellName;
|
||||
|
||||
/** The {@link ShellCreateMode} of commands. */
|
||||
public String shellCreateMode;
|
||||
|
||||
|
||||
|
||||
@@ -386,12 +387,12 @@ public class ExecutionCommand {
|
||||
if (!ignoreNull || executionCommand.sessionAction != null)
|
||||
logString.append("\n").append(executionCommand.getSessionActionLogString());
|
||||
|
||||
if (!ignoreNull || executionCommand.sessionName != null) {
|
||||
logString.append("\n").append(executionCommand.getSessionNameLogString());
|
||||
if (!ignoreNull || executionCommand.shellName != null) {
|
||||
logString.append("\n").append(executionCommand.getShellNameLogString());
|
||||
}
|
||||
|
||||
if (!ignoreNull || executionCommand.sessionCreateMode != null) {
|
||||
logString.append("\n").append(executionCommand.getSessionCreateModeLogString());
|
||||
if (!ignoreNull || executionCommand.shellCreateMode != null) {
|
||||
logString.append("\n").append(executionCommand.getShellCreateModeLogString());
|
||||
}
|
||||
|
||||
if (!ignoreNull || executionCommand.commandIntent != null)
|
||||
@@ -485,8 +486,9 @@ public class ExecutionCommand {
|
||||
}
|
||||
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Session Action", executionCommand.sessionAction, "-"));
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Session Name", executionCommand.sessionName, "-"));
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Session Create Mode", executionCommand.sessionCreateMode, "-"));
|
||||
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Shell Name", executionCommand.shellName, "-"));
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Shell Create Mode", executionCommand.shellCreateMode, "-"));
|
||||
|
||||
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("isPluginExecutionCommand", executionCommand.isPluginExecutionCommand, "-"));
|
||||
@@ -577,12 +579,12 @@ public class ExecutionCommand {
|
||||
return Logger.getSingleLineLogStringEntry("Session Action", sessionAction, "-");
|
||||
}
|
||||
|
||||
public String getSessionNameLogString() {
|
||||
return Logger.getSingleLineLogStringEntry("Session Name", sessionName, "-");
|
||||
public String getShellNameLogString() {
|
||||
return Logger.getSingleLineLogStringEntry("Shell Name", shellName, "-");
|
||||
}
|
||||
|
||||
public String getSessionCreateModeLogString() {
|
||||
return Logger.getSingleLineLogStringEntry("Session Create Mode", sessionCreateMode, "-");
|
||||
public String getShellCreateModeLogString() {
|
||||
return Logger.getSingleLineLogStringEntry("Shell Create Mode", shellCreateMode, "-");
|
||||
}
|
||||
|
||||
public String getCommandDescriptionLogString() {
|
||||
|
@@ -75,8 +75,15 @@ public final class AppShell {
|
||||
executionCommand.workingDirectory = "/";
|
||||
|
||||
String[] env = shellEnvironmentClient.buildEnvironment(context, executionCommand.isFailsafe, executionCommand.workingDirectory);
|
||||
// Transform executable path to shell/session name, e.g. "/bin/do-something.sh" => "do-something.sh".
|
||||
String executableBasename = ShellUtils.getExecutableBasename(executionCommand.executable);
|
||||
|
||||
if (executionCommand.shellName == null)
|
||||
executionCommand.shellName = executableBasename;
|
||||
|
||||
final String[] commandArray = shellEnvironmentClient.setupProcessArgs(executionCommand.executable, executionCommand.arguments);
|
||||
if (executionCommand.commandLabel == null)
|
||||
executionCommand.commandLabel = executableBasename;
|
||||
|
||||
if (!executionCommand.setState(ExecutionState.EXECUTING)) {
|
||||
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), context.getString(R.string.error_failed_to_execute_app_shell_command, executionCommand.getCommandIdAndLabelLogString()));
|
||||
@@ -88,11 +95,6 @@ public final class AppShell {
|
||||
Logger.logDebugExtended(LOG_TAG, ExecutionCommand.getExecutionInputLogString(executionCommand,
|
||||
true, Logger.shouldEnableLoggingForCustomLogLevel(executionCommand.backgroundCustomLogLevel)));
|
||||
|
||||
String taskName = ShellUtils.getExecutableBasename(executionCommand.executable);
|
||||
|
||||
if (executionCommand.commandLabel == null)
|
||||
executionCommand.commandLabel = taskName;
|
||||
|
||||
// Exec the process
|
||||
final Process process;
|
||||
try {
|
||||
|
Reference in New Issue
Block a user