Skip to content

Commit

Permalink
fix: add abort all functions in activity
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoclongdev authored Oct 4, 2024
1 parent e86ad36 commit 4f0bd2a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-snails-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"terminal-keeper": patch
---

fix: add abort all functions in activity
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
"category": "Terminal Keeper",
"title": "Clear All"
},
{
"command": "terminal-keeper.abort-all",
"category": "Terminal Keeper",
"title": "Abort All"
},
{
"command": "terminal-keeper.kill-all",
"category": "Terminal Keeper",
Expand Down Expand Up @@ -195,10 +200,15 @@
"group": "activity@2"
},
{
"command": "terminal-keeper.kill-all",
"command": "terminal-keeper.abort-all",
"when": "view == terminalKeeperActivityView",
"group": "activity@3"
},
{
"command": "terminal-keeper.kill-all",
"when": "view == terminalKeeperActivityView",
"group": "activity@4"
},
{
"command": "terminal-keeper.save",
"when": "view == terminalKeeperActivityView",
Expand Down
29 changes: 29 additions & 0 deletions src/commands/abortAllAsync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ProgressLocation, window } from 'vscode';
import { constants } from '../utils/constants';
import { showErrorMessageWithDetail } from '../utils/utils';

export const abortAllAsync = async (): Promise<void> => {
try {
window.withProgress(
{
location: ProgressLocation.Window,
title: 'Terminal Keeper',
cancellable: false
},
async (progress) => {
// If not keep existing terminals, to dispose all
progress.report({ message: 'Abort all terminals...' });

// Clear all existing terminal in parallel
window.terminals.forEach(async (terminal) => {
terminal.sendText(`\u0003`, true);
});

// Return a value when the task completes
return 'Abort all of the terminal completed!';
}
);
} catch (error) {
showErrorMessageWithDetail(constants.abortTerminalFailed, error);
}
};
4 changes: 3 additions & 1 deletion src/commands/killAllAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const killAllAsync = async (): Promise<void> => {
progress.report({ message: 'Kill all terminals...' });

// Kill all existing terminal in parallel
await killAllTerminal();
if (window.terminals && window.terminals.length > 0) {
await killAllTerminal();
}

// Return a value when the task completes
return 'Kill all of the terminal completed!';
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExtensionContext, Uri, commands, env, window } from 'vscode';
import { abortAllAsync } from './commands/abortAllAsync';
import { activeAsync } from './commands/activeAsync';
import { activeBySessionAsync } from './commands/activeBySessionAsync';
import { activeByTerminalAsync } from './commands/activeByTerminalAsync';
Expand Down Expand Up @@ -50,6 +51,10 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand(extCommands.clearAll, async (...args: any[]) => {
await clearAllAsync();
}),
// Abort all terminals
commands.registerCommand(extCommands.abortAll, async (...args: any[]) => {
await abortAllAsync();
}),
// Kill all terminals
commands.registerCommand(extCommands.killAll, async (...args: any[]) => {
await killAllAsync();
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const extCommands = {
remove: 'terminal-keeper.remove',
migrate: 'terminal-keeper.migrate',
clearAll: 'terminal-keeper.clear-all',
abortAll: 'terminal-keeper.abort-all',
killAll: 'terminal-keeper.kill-all',
refresh: 'terminal-keeper.refresh-activity',
activeSessionActivity: 'terminal-keeper.active-session-activity',
Expand Down Expand Up @@ -44,6 +45,7 @@ export const constants = {
activeTerminalFailed: 'Failed to activate the terminal.',
killTerminalFailed: 'Failed to kill the terminals.',
clearTerminalFailed: 'Failed to clear the terminals.',
abortTerminalFailed: 'Failed to abort the terminals.',
workingDirNotExist: 'The terminal "{terminal}" cannot find the current working directory "{cwd}".',

// Valid configuration file
Expand Down

0 comments on commit 4f0bd2a

Please sign in to comment.