diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index d62f604f1..5cb0d7364 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -8,6 +8,7 @@ import * as rxjs from "rxjs"; import type { WailsEvent } from "@wailsio/runtime/types/events"; import { Events } from "@wailsio/runtime"; import { produce } from "immer"; +import * as BlockService from "@/bindings/pkg/service/blockservice/BlockService"; const globalStore = jotai.createStore(); @@ -95,6 +96,7 @@ function removeBlockFromTab(tabId: string, blockId: string) { }); globalStore.set(atoms.tabsAtom, newTabArr); removeBlock(blockId); + BlockService.CloseBlock(blockId); } export { globalStore, atoms, getBlockSubject, addBlockIdToTab, blockDataMap, useBlockAtom, removeBlockFromTab }; diff --git a/pkg/blockcontroller/blockcontroller.go b/pkg/blockcontroller/blockcontroller.go index 375f0262e..20f72ac0e 100644 --- a/pkg/blockcontroller/blockcontroller.go +++ b/pkg/blockcontroller/blockcontroller.go @@ -108,6 +108,15 @@ func CreateBlock(bdef *BlockDef, rtOpts *RuntimeOpts) (*BlockData, error) { return blockData, nil } +func CloseBlock(blockId string) { + bc := GetBlockController(blockId) + if bc == nil { + return + } + bc.Close() + close(bc.InputCh) +} + func GetBlockData(blockId string) *BlockData { globalLock.Lock() defer globalLock.Unlock() @@ -140,6 +149,12 @@ type RunShellOpts struct { TermSize shellexec.TermSize `json:"termsize,omitempty"` } +func (bc *BlockController) Close() { + if bc.getShellProc() != nil { + bc.ShellProc.Close() + } +} + func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts) error { if bc.getShellProc() != nil { return nil diff --git a/pkg/service/blockservice/blockservice.go b/pkg/service/blockservice/blockservice.go index d70a64123..8606e7967 100644 --- a/pkg/service/blockservice/blockservice.go +++ b/pkg/service/blockservice/blockservice.go @@ -34,6 +34,10 @@ func (bs *BlockService) CreateBlock(bdefMap map[string]any, rtOptsMap map[string return rtnMap, nil } +func (bs *BlockService) CloseBlock(blockId string) { + blockcontroller.CloseBlock(blockId) +} + func (bs *BlockService) GetBlockData(blockId string) (map[string]any, error) { blockData := blockcontroller.GetBlockData(blockId) if blockData == nil {