Skip to content

Commit 78a99fd

Browse files
Add the TermuxSession class for linking a TerminalSession to an ExecutionCommand.
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.
1 parent dff2794 commit 78a99fd

File tree

6 files changed

+356
-189
lines changed

6 files changed

+356
-189
lines changed

app/src/main/java/com/termux/app/TermuxActivity.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void onStart() {
214214
// Get the session stored in shared preferences stored by {@link #onStop} if its valid,
215215
// otherwise get the last session currently running.
216216
mTermuxSessionClient.setCurrentSession(mTermuxSessionClient.getCurrentStoredSessionOrLast());
217-
terminalSessionListNotifyUpdated();
217+
termuxSessionListNotifyUpdated();
218218
}
219219

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

243243
setTermuxSessionsListView();
244244

245-
if (mTermuxService.getSessions().isEmpty()) {
245+
if (mTermuxService.isTermuxSessionsEmpty()) {
246246
if (mIsVisible) {
247247
TermuxInstaller.setupIfNeeded(TermuxActivity.this, () -> {
248248
if (mTermuxService == null) return; // Activity might have been destroyed.
@@ -395,9 +395,10 @@ private void setNewSessionButtonView() {
395395
View newSessionButton = findViewById(R.id.new_session_button);
396396
newSessionButton.setOnClickListener(v -> mTermuxSessionClient.addNewSession(false, null));
397397
newSessionButton.setOnLongClickListener(v -> {
398-
DialogUtils.textInput(TermuxActivity.this, R.string.title_create_named_session, null, R.string.action_create_named_session_confirm,
399-
text -> mTermuxSessionClient.addNewSession(false, text), R.string.action_new_session_failsafe, text -> mTermuxSessionClient.addNewSession(true, text)
400-
, -1, null, null);
398+
DialogUtils.textInput(TermuxActivity.this, R.string.title_create_named_session, null,
399+
R.string.action_create_named_session_confirm, text -> mTermuxSessionClient.addNewSession(false, text),
400+
R.string.action_new_session_failsafe, text -> mTermuxSessionClient.addNewSession(true, text),
401+
-1, null, null);
401402
return true;
402403
});
403404
}
@@ -439,7 +440,7 @@ private void setTermuxTerminalViewAndClients() {
439440

440441
private void setTermuxSessionsListView() {
441442
ListView termuxSessionsListView = findViewById(R.id.terminal_sessions_list);
442-
mTermuxSessionListViewController = new TermuxSessionsListViewController(this, mTermuxService.getSessions());
443+
mTermuxSessionListViewController = new TermuxSessionsListViewController(this, mTermuxService.getTermuxSessions());
443444
termuxSessionsListView.setAdapter(mTermuxSessionListViewController);
444445
termuxSessionsListView.setOnItemClickListener(mTermuxSessionListViewController);
445446
termuxSessionsListView.setOnItemLongClickListener(mTermuxSessionListViewController);
@@ -468,6 +469,7 @@ public void finishActivityIfNotFinishing() {
468469

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

645-
public void terminalSessionListNotifyUpdated() {
647+
public void termuxSessionListNotifyUpdated() {
646648
mTermuxSessionListViewController.notifyDataSetChanged();
647649
}
648650

@@ -683,6 +685,13 @@ public TermuxSharedProperties getProperties() {
683685

684686

685687

688+
public static void updateTermuxActivityStyling(Context context) {
689+
// Make sure that terminal styling is always applied.
690+
Intent stylingIntent = new Intent(TERMUX_ACTIVITY.ACTION_RELOAD_STYLE);
691+
stylingIntent.putExtra(TERMUX_ACTIVITY.EXTRA_RELOAD_STYLE, "styling");
692+
context.sendBroadcast(stylingIntent);
693+
}
694+
686695
class TermuxActivityBroadcastReceiever extends BroadcastReceiver {
687696
@Override
688697
public void onReceive(Context context, Intent intent) {

0 commit comments

Comments
 (0)