Skip to content

Commit

Permalink
fix: terminal is not restarted if container if not running + state ma…
Browse files Browse the repository at this point in the history
…nagement (podman-desktop#9793)

* fix: terminal is not restarted if container if not running + state management
Signed-off-by: Philippe Martin <[email protected]>

* refactor: containerState as $derived
Signed-off-by: Philippe Martin <[email protected]>
  • Loading branch information
feloy committed Nov 6, 2024
1 parent 5c6c6ac commit 24995e8
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/renderer/src/lib/container/ContainerDetailsTerminal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ let sendCallbackId: number | undefined;
let terminalContent: string = '';
let serializeAddon: SerializeAddon;
let lastState = $state('');
let containerState = $state(container);
let containerState = $derived(container.state);
$effect(() => {
containerState = container;
if (lastState === 'STARTING' && containerState.state === 'RUNNING') {
if (lastState === 'STARTING' && containerState === 'RUNNING') {
restartTerminal();
}
lastState = container.state;
Expand All @@ -54,16 +53,20 @@ function receiveDataCallback(data: Buffer) {
}
function receiveEndCallback() {
// need to reopen a new terminal
window
.shellInContainer(container.engineId, container.id, receiveDataCallback, () => {}, receiveEndCallback)
.then(id => {
sendCallbackId = id;
shellTerminal?.onData(data => {
window.shellInContainerSend(id, data);
// need to reopen a new terminal if container is running
if (containerState === 'RUNNING') {
window
.shellInContainer(container.engineId, container.id, receiveDataCallback, () => {}, receiveEndCallback)
.then(id => {
sendCallbackId = id;
shellTerminal?.onData(data => {
window.shellInContainerSend(id, data);
});
})
.catch((err: unknown) => {
console.error('error starting shell', err);
});
});
}
}
// call exec command
Expand Down

0 comments on commit 24995e8

Please sign in to comment.