hook up close block to backend to remove the running process

This commit is contained in:
sawka 2024-05-16 13:40:23 -07:00
parent 91d7392c34
commit b721f59166
3 changed files with 21 additions and 0 deletions

View File

@ -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 };

View File

@ -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

View File

@ -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 {