diff --git a/app/src/main/java/com/termux/app/RunCommandService.java b/app/src/main/java/com/termux/app/RunCommandService.java
index 2091f92485..1a526adb93 100644
--- a/app/src/main/java/com/termux/app/RunCommandService.java
+++ b/app/src/main/java/com/termux/app/RunCommandService.java
@@ -114,6 +114,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
executionCommand.backgroundCustomLogLevel = IntentUtils.getIntegerExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, null);
executionCommand.sessionAction = intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_SESSION_ACTION);
+ executionCommand.sessionName = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_SESSION_NAME, null);
+ executionCommand.sessionCreateMode = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_SESSION_CREATE_MODE, null);
executionCommand.commandLabel = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_LABEL, "RUN_COMMAND Execution Intent Command");
executionCommand.commandDescription = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_DESCRIPTION, null);
executionCommand.commandHelp = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_HELP, null);
@@ -209,6 +211,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
execIntent.putExtra(TERMUX_SERVICE.EXTRA_RUNNER, executionCommand.runner);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, DataUtils.getStringFromInteger(executionCommand.backgroundCustomLogLevel, null));
execIntent.putExtra(TERMUX_SERVICE.EXTRA_SESSION_ACTION, executionCommand.sessionAction);
+ execIntent.putExtra(TERMUX_SERVICE.EXTRA_SESSION_NAME, executionCommand.sessionName);
+ execIntent.putExtra(TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE, executionCommand.sessionCreateMode);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_LABEL, executionCommand.commandLabel);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_DESCRIPTION, executionCommand.commandDescription);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_HELP, executionCommand.commandHelp);
diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java
index 3e60a2c8a6..bffe71052c 100644
--- a/app/src/main/java/com/termux/app/TermuxService.java
+++ b/app/src/main/java/com/termux/app/TermuxService.java
@@ -41,6 +41,7 @@
import com.termux.shared.data.DataUtils;
import com.termux.shared.shell.command.ExecutionCommand;
import com.termux.shared.shell.command.ExecutionCommand.Runner;
+import com.termux.shared.shell.command.ExecutionCommand.SessionCreateMode;
import com.termux.terminal.TerminalEmulator;
import com.termux.terminal.TerminalSession;
import com.termux.terminal.TerminalSessionClient;
@@ -380,6 +381,8 @@ private void actionServiceExecute(Intent intent) {
executionCommand.workingDirectory = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_WORKDIR, null);
executionCommand.isFailsafe = intent.getBooleanExtra(TERMUX_ACTIVITY.EXTRA_FAILSAFE_SESSION, false);
executionCommand.sessionAction = intent.getStringExtra(TERMUX_SERVICE.EXTRA_SESSION_ACTION);
+ executionCommand.sessionName = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_SESSION_NAME, null);
+ executionCommand.sessionCreateMode = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE, null);
executionCommand.commandLabel = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_COMMAND_LABEL, "Execution Intent Command");
executionCommand.commandDescription = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_COMMAND_DESCRIPTION, null);
executionCommand.commandHelp = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_COMMAND_HELP, null);
@@ -398,13 +401,13 @@ private void actionServiceExecute(Intent intent) {
mPendingPluginExecutionCommands.add(executionCommand);
if (Runner.APP_SHELL.equalsRunner(executionCommand.runner))
- executeTermuxTaskCommand(executionCommand);
+ executeTermuxTaskCommand(executionCommand);
else if (Runner.TERMINAL_SESSION.equalsRunner(executionCommand.runner))
- executeTermuxSessionCommand(executionCommand);
+ executeTermuxSessionCommand(executionCommand);
else {
- String errmsg = this.getString(R.string.error_termux_service_unsupported_execution_command_runner, executionCommand.runner);
- executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
- PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
+ String errmsg = getString(R.string.error_termux_service_unsupported_execution_command_runner, executionCommand.runner);
+ executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
+ PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
}
}
@@ -493,16 +496,39 @@ public void onAppShellExited(final AppShell termuxTask) {
private void executeTermuxSessionCommand(ExecutionCommand executionCommand) {
if (executionCommand == null) return;
+ if (executionCommand.sessionCreateMode == null)
+ executionCommand.sessionCreateMode = SessionCreateMode.ALWAYS.getMode();
+
Logger.logDebug(LOG_TAG, "Executing foreground \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession command");
- String sessionName = null;
+ // Transform executable path to session name, e.g. "/bin/do-something.sh" => "do-something.sh".
+ if (executionCommand.sessionName == null && executionCommand.executable != null) {
+ executionCommand.sessionName = ShellUtils.getExecutableBasename(executionCommand.executable);
+ }
- // Transform executable path to session name, e.g. "/bin/do-something.sh" => "do something.sh".
- if (executionCommand.executable != null) {
- sessionName = ShellUtils.getExecutableBasename(executionCommand.executable).replace('-', ' ');
+ TermuxSession newTermuxSession = null;
+ if (SessionCreateMode.ALWAYS.equalsMode(executionCommand.sessionCreateMode))
+ ; // Default
+ else if (SessionCreateMode.NO_SESSION_WITH_NAME.equalsMode(executionCommand.sessionCreateMode))
+ if (DataUtils.isNullOrEmpty(executionCommand.sessionName)) {
+ String errmsg = getString(R.string.error_termux_service_execution_command_session_name_unset, executionCommand.sessionCreateMode);
+ executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
+ PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
+ return;
+ } else {
+ newTermuxSession = getTermuxSessionForName(executionCommand.sessionName);
+ if (newTermuxSession != null)
+ Logger.logInfo(LOG_TAG, "Existing session with \"" + executionCommand.sessionName + "\" session name found");
+ }
+ else {
+ String errmsg = getString(R.string.error_termux_service_unsupported_execution_command_session_create_mode, executionCommand.sessionCreateMode);
+ executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
+ PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
+ return;
}
- TermuxSession newTermuxSession = createTermuxSession(executionCommand, sessionName);
+ if (newTermuxSession == null)
+ newTermuxSession = createTermuxSession(executionCommand);
if (newTermuxSession == null) return;
handleSessionAction(DataUtils.getIntFromString(executionCommand.sessionAction,
@@ -516,12 +542,14 @@ private void executeTermuxSessionCommand(ExecutionCommand executionCommand) {
*/
@Nullable
public TermuxSession createTermuxSession(String executablePath, String[] arguments, String stdin, String workingDirectory, boolean isFailSafe, String sessionName) {
- return createTermuxSession(new ExecutionCommand(getNextExecutionId(), executablePath, arguments, stdin, workingDirectory, Runner.TERMINAL_SESSION.getName(), isFailSafe), sessionName);
+ ExecutionCommand executionCommand = new ExecutionCommand(getNextExecutionId(), executablePath, arguments, stdin, workingDirectory, Runner.TERMINAL_SESSION.getName(), isFailSafe);
+ executionCommand.sessionName = sessionName;
+ return createTermuxSession(executionCommand);
}
/** Create a {@link TermuxSession}. */
@Nullable
- public synchronized TermuxSession createTermuxSession(ExecutionCommand executionCommand, String sessionName) {
+ public synchronized TermuxSession createTermuxSession(ExecutionCommand executionCommand) {
if (executionCommand == null) return null;
Logger.logDebug(LOG_TAG, "Creating \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession");
@@ -538,7 +566,7 @@ public synchronized TermuxSession createTermuxSession(ExecutionCommand execution
// Otherwise if command was manually started by the user like by adding a new terminal session,
// then no need to set stdout
executionCommand.terminalTranscriptRows = mProperties.getTerminalTranscriptRows();
- TermuxSession newTermuxSession = TermuxSession.execute(this, executionCommand, getTermuxTerminalSessionClient(), this, new TermuxShellEnvironmentClient(), sessionName, executionCommand.isPluginExecutionCommand);
+ TermuxSession newTermuxSession = TermuxSession.execute(this, executionCommand, getTermuxTerminalSessionClient(), this, new TermuxShellEnvironmentClient(), executionCommand.isPluginExecutionCommand);
if (newTermuxSession == null) {
Logger.logError(LOG_TAG, "Failed to execute new TermuxSession command for:\n" + executionCommand.getCommandIdAndLabelLogString());
// If the execution command was started for a plugin, then process the error
@@ -852,6 +880,18 @@ public synchronized TerminalSession getTerminalSessionForHandle(String sessionHa
return null;
}
+ public synchronized TermuxSession getTermuxSessionForName(String name) {
+ if (DataUtils.isNullOrEmpty(name)) return null;
+ TermuxSession termuxSession;
+ for (int i = 0, len = mTermuxSessions.size(); i < len; i++) {
+ termuxSession = mTermuxSessions.get(i);
+ TerminalSession terminalSession = termuxSession.getTerminalSession();
+ if (terminalSession.mSessionName != null && terminalSession.mSessionName.equals(name))
+ return termuxSession;
+ }
+ return null;
+ }
+
public static synchronized int getNextExecutionId() {
diff --git a/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java b/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java
index e15b6e7d8d..070872d7d0 100644
--- a/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java
+++ b/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java
@@ -345,11 +345,22 @@ public void renameSession(final TerminalSession sessionToRename) {
if (sessionToRename == null) return;
TextInputDialogUtils.textInput(mActivity, R.string.title_rename_session, sessionToRename.mSessionName, R.string.action_rename_session_confirm, text -> {
- sessionToRename.mSessionName = text;
+ renameSession(sessionToRename, text);
termuxSessionListNotifyUpdated();
}, -1, null, -1, null, null);
}
+ private void renameSession(TerminalSession sessionToRename, String text) {
+ if (sessionToRename == null) return;
+ sessionToRename.mSessionName = text;
+ TermuxService service = mActivity.getTermuxService();
+ if (service != null) {
+ TermuxSession termuxSession = service.getTermuxSessionForTerminalSession(sessionToRename);
+ if (termuxSession != null)
+ termuxSession.getExecutionCommand().sessionName = text;
+ }
+ }
+
public void addNewSession(boolean isFailSafe, String sessionName) {
TermuxService service = mActivity.getTermuxService();
if (service == null) return;
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0a6c02dcaf..e49b4e8585 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -100,6 +100,8 @@
Grants it from Settings -> Apps -> &TERMUX_APP_NAME; -> Advanced
Invalid execution command runner to TermuxService: `%1$s`
Unsupported execution command runner to TermuxService: `%1$s`
+ Unsupported execution command session create mode to TermuxService: `%1$s`
+ Session name not set but `%1$s` session create mode passed
diff --git a/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java b/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java
index 90c1fba4bc..2ee38283e5 100644
--- a/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java
+++ b/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java
@@ -105,6 +105,41 @@ public static Runner runnerOf(@Nullable String name, @NonNull Runner def) {
}
+ public enum SessionCreateMode {
+
+ /** Always create {@link TerminalSession}. */
+ ALWAYS("always"),
+
+ /** Create session only if no session with {@link #sessionName} found. */
+ NO_SESSION_WITH_NAME("no-session-with-name");
+
+ private final String mode;
+
+ SessionCreateMode(final String mode) {
+ this.mode = mode;
+ }
+
+ public String getMode() {
+ return mode;
+ }
+
+ public boolean equalsMode(String sessionCreateMode) {
+ return sessionCreateMode != null && sessionCreateMode.equals(this.mode);
+ }
+
+ /** Get {@link SessionCreateMode} for {@code mode} if found, otherwise {@code null}. */
+ @Nullable
+ public static SessionCreateMode modeOf(String mode) {
+ for (SessionCreateMode v : SessionCreateMode.values()) {
+ if (v.mode.equals(mode)) {
+ return v;
+ }
+ }
+ return null;
+ }
+
+ }
+
/** The optional unique id for the {@link ExecutionCommand}. */
public Integer id;
@@ -148,9 +183,17 @@ public static Runner runnerOf(@Nullable String name, @NonNull Runner def) {
*/
public Integer backgroundCustomLogLevel;
- /** The session action of foreground commands. */
+
+ /** 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 command label for the {@link ExecutionCommand}. */
public String commandLabel;
@@ -343,6 +386,14 @@ public static String getExecutionInputLogString(final ExecutionCommand execution
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.sessionCreateMode != null) {
+ logString.append("\n").append(executionCommand.getSessionCreateModeLogString());
+ }
+
if (!ignoreNull || executionCommand.commandIntent != null)
logString.append("\n").append(executionCommand.getCommandIntentLogString());
@@ -434,6 +485,8 @@ public static String getExecutionCommandMarkdownString(final ExecutionCommand ex
}
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("isPluginExecutionCommand", executionCommand.isPluginExecutionCommand, "-"));
@@ -524,6 +577,14 @@ public String getSessionActionLogString() {
return Logger.getSingleLineLogStringEntry("Session Action", sessionAction, "-");
}
+ public String getSessionNameLogString() {
+ return Logger.getSingleLineLogStringEntry("Session Name", sessionName, "-");
+ }
+
+ public String getSessionCreateModeLogString() {
+ return Logger.getSingleLineLogStringEntry("Session Create Mode", sessionCreateMode, "-");
+ }
+
public String getCommandDescriptionLogString() {
return Logger.getSingleLineLogStringEntry("Command Description", commandDescription, "-");
}
diff --git a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java
index 3c5e0a8e91..68ec885cc6 100644
--- a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java
+++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java
@@ -2,13 +2,16 @@
import android.annotation.SuppressLint;
+import com.termux.shared.shell.command.ExecutionCommand;
+import com.termux.shared.shell.command.ExecutionCommand.Runner;
+
import java.io.File;
import java.util.Arrays;
import java.util.Formatter;
import java.util.List;
/*
- * Version: v0.38.0
+ * Version: v0.39.0
* SPDX-License-Identifier: MIT
*
* Changelog
@@ -226,6 +229,10 @@
*
* - 0.38.0 (2022-03-16)
* - Added `TERMUX_APP.TERMUX_ACTIVITY.ACTION_NOTIFY_APP_CRASH`.
+ *
+ * - 0.39.0 (2022-03-18)
+ * - Added `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_NAME`, `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_NAME`,
+ * `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE` and `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_CREATE_MODE`.
*/
/**
@@ -937,15 +944,19 @@ public static final class TERMUX_SERVICE {
public static final String EXTRA_STDIN = TERMUX_PACKAGE_NAME + ".execute.stdin"; // Default: "com.termux.execute.stdin"
/** Intent {@code String} extra for command current working directory for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
public static final String EXTRA_WORKDIR = TERMUX_PACKAGE_NAME + ".execute.cwd"; // Default: "com.termux.execute.cwd"
- /** Intent {@code boolean} extra for command background mode for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
+ /** Intent {@code boolean} extra for whether to run command in background {@link Runner#APP_SHELL} or foreground {@link Runner#TERMINAL_SESSION} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
@Deprecated
public static final String EXTRA_BACKGROUND = TERMUX_PACKAGE_NAME + ".execute.background"; // Default: "com.termux.execute.background"
- /** Intent {@code boolean} extra for command the {@link com.termux.shared.shell.command.ExecutionCommand.Runner} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
+ /** Intent {@code String} extra for command the {@link Runner} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
public static final String EXTRA_RUNNER = TERMUX_PACKAGE_NAME + ".execute.runner"; // Default: "com.termux.execute.runner"
/** Intent {@code String} extra for custom log level for background commands defined by {@link com.termux.shared.logger.Logger} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
public static final String EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL = TERMUX_PACKAGE_NAME + ".execute.background_custom_log_level"; // Default: "com.termux.execute.background_custom_log_level"
- /** Intent {@code String} extra for session action for foreground commands for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
+ /** Intent {@code String} extra for session action for {@link Runner#TERMINAL_SESSION} commands for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
public static final String EXTRA_SESSION_ACTION = TERMUX_PACKAGE_NAME + ".execute.session_action"; // Default: "com.termux.execute.session_action"
+ /** Intent {@code String} extra for session name for {@link Runner#TERMINAL_SESSION} commands for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
+ public static final String EXTRA_SESSION_NAME = TERMUX_PACKAGE_NAME + ".execute.session_name"; // Default: "com.termux.execute.session_name"
+ /** Intent {@code String} extra for the {@link ExecutionCommand.SessionCreateMode} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent. */
+ public static final String EXTRA_SESSION_CREATE_MODE = TERMUX_PACKAGE_NAME + ".execute.session_create_mode"; // Default: "com.termux.execute.session_create_mode"
/** Intent {@code String} extra for label of the command for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
public static final String EXTRA_COMMAND_LABEL = TERMUX_PACKAGE_NAME + ".execute.command_label"; // Default: "com.termux.execute.command_label"
/** Intent markdown {@code String} extra for description of the command for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
@@ -981,20 +992,23 @@ public static final class TERMUX_SERVICE {
- /** The value for {@link #EXTRA_SESSION_ACTION} extra that will set the new session as
+ /**
+ * The value for {@link #EXTRA_SESSION_ACTION} extra that will set the new session as
* the current session and will start {@link TERMUX_ACTIVITY} if its not running to bring
* the new session to foreground.
*/
public static final int VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY = 0;
- /** The value for {@link #EXTRA_SESSION_ACTION} extra that will keep any existing session
+ /**
+ * The value for {@link #EXTRA_SESSION_ACTION} extra that will keep any existing session
* as the current session and will start {@link TERMUX_ACTIVITY} if its not running to
* bring the existing session to foreground. The new session will be added to the left
* sidebar in the sessions list.
*/
public static final int VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY = 1;
- /** The value for {@link #EXTRA_SESSION_ACTION} extra that will set the new session as
+ /**
+ * The value for {@link #EXTRA_SESSION_ACTION} extra that will set the new session as
* the current session but will not start {@link TERMUX_ACTIVITY} if its not running
* and session(s) will be seen in Termux notification and can be clicked to bring new
* session to foreground. If the {@link TERMUX_ACTIVITY} is already running, then this
@@ -1002,7 +1016,8 @@ public static final class TERMUX_SERVICE {
*/
public static final int VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_DONT_OPEN_ACTIVITY = 2;
- /** The value for {@link #EXTRA_SESSION_ACTION} extra that will keep any existing session
+ /**
+ * The value for {@link #EXTRA_SESSION_ACTION} extra that will keep any existing session
* as the current session but will not start {@link TERMUX_ACTIVITY} if its not running
* and session(s) will be seen in Termux notification and can be clicked to bring
* existing session to foreground. If the {@link TERMUX_ACTIVITY} is already running,
@@ -1070,15 +1085,19 @@ public static final class RUN_COMMAND_SERVICE {
public static final String EXTRA_STDIN = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_STDIN"; // Default: "com.termux.RUN_COMMAND_STDIN"
/** Intent {@code String} extra for current working directory of command for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
public static final String EXTRA_WORKDIR = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_WORKDIR"; // Default: "com.termux.RUN_COMMAND_WORKDIR"
- /** Intent {@code boolean} extra for whether to run command in background or foreground terminal session for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
+ /** Intent {@code boolean} extra for whether to run command in background {@link Runner#APP_SHELL} or foreground {@link Runner#TERMINAL_SESSION} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
@Deprecated
public static final String EXTRA_BACKGROUND = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_BACKGROUND"; // Default: "com.termux.RUN_COMMAND_BACKGROUND"
- /** Intent {@code boolean} extra for command the {@link com.termux.shared.shell.command.ExecutionCommand.Runner} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
+ /** Intent {@code String} extra for command the {@link Runner} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
public static final String EXTRA_RUNNER = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_RUNNER"; // Default: "com.termux.RUN_COMMAND_RUNNER"
/** Intent {@code String} extra for custom log level for background commands defined by {@link com.termux.shared.logger.Logger} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
public static final String EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL"; // Default: "com.termux.RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL"
- /** Intent {@code String} extra for session action of foreground commands for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
+ /** Intent {@code String} extra for session action of {@link Runner#TERMINAL_SESSION} commands for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
public static final String EXTRA_SESSION_ACTION = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SESSION_ACTION"; // Default: "com.termux.RUN_COMMAND_SESSION_ACTION"
+ /** Intent {@code String} extra for session name of {@link Runner#TERMINAL_SESSION} commands for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
+ public static final String EXTRA_SESSION_NAME = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SESSION_NAME"; // Default: "com.termux.RUN_COMMAND_SESSION_NAME"
+ /** Intent {@code String} extra for the {@link ExecutionCommand.SessionCreateMode} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent. */
+ public static final String EXTRA_SESSION_CREATE_MODE = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SESSION_CREATE_MODE"; // Default: "com.termux.RUN_COMMAND_SESSION_CREATE_MODE"
/** Intent {@code String} extra for label of the command for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
public static final String EXTRA_COMMAND_LABEL = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_COMMAND_LABEL"; // Default: "com.termux.RUN_COMMAND_COMMAND_LABEL"
/** Intent markdown {@code String} extra for description of the command for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
diff --git a/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java b/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java
index 76e62c7c84..2cfeb45d58 100644
--- a/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java
+++ b/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java
@@ -54,7 +54,6 @@ private TermuxSession(@NonNull final TerminalSession terminalSession, @NonNull f
* @param terminalSessionClient The {@link TerminalSessionClient} interface implementation.
* @param termuxSessionClient The {@link TermuxSessionClient} interface implementation.
* @param shellEnvironmentClient The {@link ShellEnvironmentClient} interface implementation.
- * @param sessionName The optional {@link TerminalSession} name.
* @param setStdoutOnExit If set to {@code true}, then the {@link ResultData#stdout}
* available in the {@link TermuxSessionClient#onTermuxSessionExited(TermuxSession)}
* callback will be set to the {@link TerminalSession} transcript. The session
@@ -67,7 +66,7 @@ private TermuxSession(@NonNull final TerminalSession terminalSession, @NonNull f
public static TermuxSession execute(@NonNull final Context context, @NonNull ExecutionCommand executionCommand,
@NonNull final TerminalSessionClient terminalSessionClient, final TermuxSessionClient termuxSessionClient,
@NonNull final ShellEnvironmentClient shellEnvironmentClient,
- final String sessionName, final boolean setStdoutOnExit) {
+ final boolean setStdoutOnExit) {
if (executionCommand.workingDirectory == null || executionCommand.workingDirectory.isEmpty())
executionCommand.workingDirectory = shellEnvironmentClient.getDefaultWorkingDirectoryPath();
if (executionCommand.workingDirectory.isEmpty())
@@ -132,8 +131,8 @@ public static TermuxSession execute(@NonNull final Context context, @NonNull Exe
Logger.logDebug(LOG_TAG, "Running \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession");
TerminalSession terminalSession = new TerminalSession(executionCommand.executable, executionCommand.workingDirectory, executionCommand.arguments, environment, executionCommand.terminalTranscriptRows, terminalSessionClient);
- if (sessionName != null) {
- terminalSession.mSessionName = sessionName;
+ if (executionCommand.sessionName != null) {
+ terminalSession.mSessionName = executionCommand.sessionName;
}
return new TermuxSession(terminalSession, executionCommand, termuxSessionClient, setStdoutOnExit);