Skip to content

Commit 9587043

Browse files
committed
Fix tasks been killed after window reload on desktop
1 parent 4e069a6 commit 9587043

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

gitpod-shared/src/features.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -629,23 +629,15 @@ export async function registerTasks(context: GitpodExtensionContext): Promise<vo
629629
const taskTerminal = taskTerminals.get(alias);
630630
if (taskTerminal) {
631631
const openMode: TerminalOpenMode | undefined = taskStatus.getPresentation()?.getOpenMode() as TerminalOpenMode;
632-
const parentTerminal = (openMode && openMode !== 'tab-before' && openMode !== 'tab-after') ? prevTerminal : undefined;
633-
const pty = createTaskPty(alias, context, token);
634-
635-
const terminal = vscode.window.createTerminal({
636-
name: taskTerminal.getTitle(),
637-
pty,
638-
iconPath: new vscode.ThemeIcon('terminal'),
639-
location: parentTerminal ? { parentTerminal } : vscode.TerminalLocation.Panel
640-
});
632+
const terminal = createTaskTerminal(taskTerminal, prevTerminal, openMode, alias, context, token);
641633
prevTerminal = terminal;
642634
}
643635
}
644636
// Focus last created terminal
645637
prevTerminal?.show();
646638
}
647639

648-
function createTaskPty(alias: string, context: GitpodExtensionContext, contextToken: vscode.CancellationToken): vscode.Pseudoterminal {
640+
function createTaskTerminal(taskTerminal: SupervisorTerminal, prevTerminal: vscode.Terminal | undefined, openMode: TerminalOpenMode, alias: string, context: GitpodExtensionContext, contextToken: vscode.CancellationToken): vscode.Terminal {
649641
const tokenSource = new vscode.CancellationTokenSource();
650642
contextToken.onCancellationRequested(() => tokenSource.cancel());
651643
const token = tokenSource.token;
@@ -656,6 +648,7 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
656648
const toDispose = vscode.Disposable.from(onDidWriteEmitter, onDidCloseEmitter, onDidChangeNameEmitter);
657649
token.onCancellationRequested(() => toDispose.dispose());
658650

651+
let terminal: vscode.Terminal
659652
let pendingWrite = Promise.resolve();
660653
let pendingResize = Promise.resolve();
661654
const pty: vscode.Pseudoterminal = {
@@ -732,13 +725,15 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
732725
return;
733726
}
734727
tokenSource.cancel();
735-
736-
// await to make sure that close is not cause by the extension host process termination
737-
// in such case we don't want to stop supervisor terminals
728+
// wait next tick to ensure terminal has exitStatus
738729
setTimeout(async () => {
739730
if (contextToken.isCancellationRequested) {
740731
return;
741732
}
733+
// we don't close tasks if terminal is closed by window reload
734+
if (terminal.exitStatus?.reason === vscode.TerminalExitReason.Shutdown) {
735+
return;
736+
}
742737
// Attempt to kill the pty, it may have already been killed at this
743738
// point but we want to make sure
744739
try {
@@ -756,8 +751,7 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
756751
console.error(`${alias} terminal: shutdown failed:`, e);
757752
}
758753
}
759-
}, 1000);
760-
754+
}, 0)
761755
},
762756
handleInput: async (data: string) => {
763757
if (token.isCancellationRequested) {
@@ -811,8 +805,16 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
811805
});
812806
}
813807
};
808+
const parentTerminal = (openMode && openMode !== 'tab-before' && openMode !== 'tab-after') ? prevTerminal : undefined;
809+
810+
terminal = vscode.window.createTerminal({
811+
name: taskTerminal.getTitle(),
812+
pty,
813+
iconPath: new vscode.ThemeIcon('terminal'),
814+
location: parentTerminal ? { parentTerminal } : vscode.TerminalLocation.Panel
815+
});
814816

815-
return pty;
817+
return terminal;
816818
}
817819

818820
/**

0 commit comments

Comments
 (0)