Skip to content

Commit

Permalink
Add the TermuxSession class for linking a TerminalSession to an Execu…
Browse files Browse the repository at this point in the history
…tionCommand.

TermuxSession will maintain info for foreground Termux sessions. Each terminal session started by TermuxService will now be linked to a ExectionCommand that started it.

This also fixes bugs where newly created session in some cases were not being automatically selected and scrolled to, like when adding a named or failsafe session or those which were created for executable intents.
  • Loading branch information
agnostic-apollo committed Mar 24, 2021
1 parent dff2794 commit 78a99fd
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 189 deletions.
23 changes: 16 additions & 7 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void onStart() {
// Get the session stored in shared preferences stored by {@link #onStop} if its valid,
// otherwise get the last session currently running.
mTermuxSessionClient.setCurrentSession(mTermuxSessionClient.getCurrentStoredSessionOrLast());
terminalSessionListNotifyUpdated();
termuxSessionListNotifyUpdated();
}

registerReceiver(mTermuxActivityBroadcastReceiever, new IntentFilter(TERMUX_ACTIVITY.ACTION_RELOAD_STYLE));
Expand Down Expand Up @@ -242,7 +242,7 @@ public void onServiceConnected(ComponentName componentName, IBinder service) {

setTermuxSessionsListView();

if (mTermuxService.getSessions().isEmpty()) {
if (mTermuxService.isTermuxSessionsEmpty()) {
if (mIsVisible) {
TermuxInstaller.setupIfNeeded(TermuxActivity.this, () -> {
if (mTermuxService == null) return; // Activity might have been destroyed.
Expand Down Expand Up @@ -395,9 +395,10 @@ private void setNewSessionButtonView() {
View newSessionButton = findViewById(R.id.new_session_button);
newSessionButton.setOnClickListener(v -> mTermuxSessionClient.addNewSession(false, null));
newSessionButton.setOnLongClickListener(v -> {
DialogUtils.textInput(TermuxActivity.this, R.string.title_create_named_session, null, R.string.action_create_named_session_confirm,
text -> mTermuxSessionClient.addNewSession(false, text), R.string.action_new_session_failsafe, text -> mTermuxSessionClient.addNewSession(true, text)
, -1, null, null);
DialogUtils.textInput(TermuxActivity.this, R.string.title_create_named_session, null,
R.string.action_create_named_session_confirm, text -> mTermuxSessionClient.addNewSession(false, text),
R.string.action_new_session_failsafe, text -> mTermuxSessionClient.addNewSession(true, text),
-1, null, null);
return true;
});
}
Expand Down Expand Up @@ -439,7 +440,7 @@ private void setTermuxTerminalViewAndClients() {

private void setTermuxSessionsListView() {
ListView termuxSessionsListView = findViewById(R.id.terminal_sessions_list);
mTermuxSessionListViewController = new TermuxSessionsListViewController(this, mTermuxService.getSessions());
mTermuxSessionListViewController = new TermuxSessionsListViewController(this, mTermuxService.getTermuxSessions());
termuxSessionsListView.setAdapter(mTermuxSessionListViewController);
termuxSessionsListView.setOnItemClickListener(mTermuxSessionListViewController);
termuxSessionsListView.setOnItemLongClickListener(mTermuxSessionListViewController);
Expand Down Expand Up @@ -468,6 +469,7 @@ public void finishActivityIfNotFinishing() {

/** Show a toast and dismiss the last one if still visible. */
public void showToast(String text, boolean longDuration) {
if(text == null || text.isEmpty()) return;
if (mLastToast != null) mLastToast.cancel();
mLastToast = Toast.makeText(TermuxActivity.this, text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
mLastToast.setGravity(Gravity.TOP, 0, 0);
Expand Down Expand Up @@ -642,7 +644,7 @@ public DrawerLayout getDrawer() {
return (DrawerLayout) findViewById(R.id.drawer_layout);
}

public void terminalSessionListNotifyUpdated() {
public void termuxSessionListNotifyUpdated() {
mTermuxSessionListViewController.notifyDataSetChanged();
}

Expand Down Expand Up @@ -683,6 +685,13 @@ public TermuxSharedProperties getProperties() {



public static void updateTermuxActivityStyling(Context context) {
// Make sure that terminal styling is always applied.
Intent stylingIntent = new Intent(TERMUX_ACTIVITY.ACTION_RELOAD_STYLE);
stylingIntent.putExtra(TERMUX_ACTIVITY.EXTRA_RELOAD_STYLE, "styling");
context.sendBroadcast(stylingIntent);
}

class TermuxActivityBroadcastReceiever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Expand Down
Loading

0 comments on commit 78a99fd

Please sign in to comment.