Skip to content

Commit d0a3534

Browse files
committed
gitbash flow working (switching between local conns)
1 parent 3ee15f5 commit d0a3534

5 files changed

Lines changed: 19 additions & 26 deletions

File tree

frontend/app/block/blockframe.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ const BlockFrame_Header = ({
254254
icon: "link-slash",
255255
title: "wsh is not installed for this connection",
256256
};
257-
const showNoWshButton = manageConnection && wshProblem && !util.isBlank(connName) && !connName.startsWith("aws:");
257+
const showNoWshButton =
258+
manageConnection && wshProblem && !util.isLocalConnName(connName) && !connName.startsWith("aws:");
258259

259260
return (
260261
<div
@@ -600,7 +601,7 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => {
600601
return;
601602
}
602603
const connName = blockData?.meta?.connection;
603-
if (!util.isBlank(connName)) {
604+
if (!util.isLocalConnName(connName)) {
604605
console.log("ensure conn", nodeModel.blockId, connName);
605606
RpcApi.ConnEnsureCommand(
606607
TabRpcClient,

frontend/app/modals/conntypeahead.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@
33

44
import { computeConnColorNum } from "@/app/block/blockutil";
55
import { TypeAheadModal } from "@/app/modals/typeaheadmodal";
6-
import {
7-
atoms,
8-
createBlock,
9-
getApi,
10-
getConnStatusAtom,
11-
getHostName,
12-
getUserName,
13-
globalStore,
14-
WOS,
15-
} from "@/app/store/global";
166
import { ConnectionsModel } from "@/app/store/connections-model";
7+
import { atoms, createBlock, getConnStatusAtom, getHostName, getUserName, globalStore, WOS } from "@/app/store/global";
178
import { globalRefocusWithTimeout } from "@/app/store/keymodel";
189
import { RpcApi } from "@/app/store/wshclientapi";
1910
import { TabRpcClient } from "@/app/store/wshrpcutil";
@@ -108,7 +99,7 @@ function createFilteredLocalSuggestionItem(
10899
iconColor: "var(--grey-text-color)",
109100
value: "",
110101
label: localName,
111-
current: connection == null,
102+
current: util.isBlank(connection),
112103
};
113104
return [localSuggestion];
114105
}
@@ -179,7 +170,7 @@ function getLocalSuggestions(
179170
const wslFiltered = filterConnections(connList, connSelected, fullConfig, filterOutNowsh);
180171
const wslSuggestionItems = createWslSuggestionItems(wslFiltered, connection, connStatusMap);
181172
const localSuggestionItem = createFilteredLocalSuggestionItem(localName, connection, connSelected);
182-
173+
183174
const gitBashItems: Array<SuggestionConnectionItem> = [];
184175
if (hasGitBash && "Git Bash".toLowerCase().includes(connSelected.toLowerCase())) {
185176
gitBashItems.push({
@@ -191,7 +182,7 @@ function getLocalSuggestions(
191182
current: connection === "local:gitbash",
192183
});
193184
}
194-
185+
195186
const combinedSuggestionItems = [...localSuggestionItem, ...gitBashItems, ...wslSuggestionItems];
196187
const sortedSuggestionItems = sortConnSuggestionItems(combinedSuggestionItems, fullConfig);
197188
if (sortedSuggestionItems.length == 0) {
@@ -250,7 +241,7 @@ function getDisconnectItem(
250241
connection: string,
251242
connStatusMap: Map<string, ConnStatus>
252243
): SuggestionConnectionItem | null {
253-
if (!connection) {
244+
if (util.isLocalConnName(connection)) {
254245
return null;
255246
}
256247
const connStatus = connStatusMap.get(connection);
@@ -418,7 +409,7 @@ const ChangeConnectionBlockModal = React.memo(
418409
oref: WOS.makeORef("block", blockId),
419410
meta: { connection: connName, file: newFile, "cmd:cwd": null },
420411
});
421-
412+
422413
try {
423414
await RpcApi.ConnEnsureCommand(
424415
TabRpcClient,

pkg/blockcontroller/blockcontroller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ func getController(blockId string) Controller {
8383

8484
func registerController(blockId string, controller Controller) {
8585
var existingController Controller
86-
86+
8787
registryLock.Lock()
8888
existing, exists := controllerRegistry[blockId]
8989
if exists {
9090
existingController = existing
9191
}
9292
controllerRegistry[blockId] = controller
9393
registryLock.Unlock()
94-
94+
9595
if existingController != nil {
9696
existingController.Stop(false, Status_Done)
9797
wstore.DeleteRTInfo(waveobj.MakeORef(waveobj.OType_Block, blockId))
@@ -169,8 +169,9 @@ func ResyncController(ctx context.Context, tabId string, blockId string, rtOpts
169169
// For shell/cmd, check if connection changed
170170
if !needsReplace && (controllerName == BlockController_Shell || controllerName == BlockController_Cmd) {
171171
connName := blockData.Meta.GetString(waveobj.MetaKey_Connection, "")
172+
// Check if connection changed, including between different local connections
172173
if existingStatus.ShellProcStatus == Status_Running && existingStatus.ShellProcConnName != connName {
173-
log.Printf("stopping blockcontroller %s due to conn change\n", blockId)
174+
log.Printf("stopping blockcontroller %s due to conn change (from %q to %q)\n", blockId, existingStatus.ShellProcConnName, connName)
174175
StopBlockControllerAndSetStatus(blockId, Status_Init)
175176
time.Sleep(100 * time.Millisecond)
176177
// Don't delete, will reuse same controller type
@@ -209,7 +210,7 @@ func ResyncController(ctx context.Context, tabId string, blockId string, rtOpts
209210
// Check if we need to start/restart
210211
status := controller.GetRuntimeStatus()
211212
if status.ShellProcStatus == Status_Init || status.ShellProcStatus == Status_Done {
212-
// For shell/cmd, check connection status first
213+
// For shell/cmd, check connection status first (for non-local connections)
213214
if controllerName == BlockController_Shell || controllerName == BlockController_Cmd {
214215
connName := blockData.Meta.GetString(waveobj.MetaKey_Connection, "")
215216
if !conncontroller.IsLocalConnName(connName) {

pkg/blockcontroller/shellcontroller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ func (bc *ShellController) setupAndStartShellProcess(logCtx context.Context, rc
483483
}
484484
cmdOpts.ShellPath = connUnion.ShellPath
485485
cmdOpts.ShellOpts = getLocalShellOpts(blockMeta)
486-
shellProc, err = shellexec.StartLocalShellProc(logCtx, rc.TermSize, cmdStr, cmdOpts)
486+
shellProc, err = shellexec.StartLocalShellProc(logCtx, rc.TermSize, cmdStr, cmdOpts, remoteName)
487487
if err != nil {
488488
return nil, err
489489
}
@@ -656,7 +656,7 @@ func getLocalShellPath(blockMeta waveobj.MetaMapType) (string, error) {
656656
if shellPath != "" {
657657
return shellPath, nil
658658
}
659-
659+
660660
connName := blockMeta.GetString(waveobj.MetaKey_Connection, "")
661661
if strings.HasPrefix(connName, "local:") {
662662
variant := strings.TrimPrefix(connName, "local:")
@@ -673,7 +673,7 @@ func getLocalShellPath(blockMeta waveobj.MetaMapType) (string, error) {
673673
}
674674
return "", fmt.Errorf("unsupported local connection type: %q", connName)
675675
}
676-
676+
677677
settings := wconfig.GetWatcher().GetFullConfig().Settings
678678
if settings.TermLocalShellPath != "" {
679679
return settings.TermLocalShellPath, nil

pkg/shellexec/shellexec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func StartRemoteShellProc(ctx context.Context, logCtx context.Context, termSize
459459
return &ShellProc{Cmd: sessionWrap, ConnName: conn.GetName(), CloseOnce: &sync.Once{}, DoneCh: make(chan any)}, nil
460460
}
461461

462-
func StartLocalShellProc(logCtx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType) (*ShellProc, error) {
462+
func StartLocalShellProc(logCtx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, connName string) (*ShellProc, error) {
463463
shellutil.InitCustomShellStartupFiles()
464464
var ecmd *exec.Cmd
465465
var shellOpts []string
@@ -562,7 +562,7 @@ func StartLocalShellProc(logCtx context.Context, termSize waveobj.TermSize, cmdS
562562
return nil, err
563563
}
564564
cmdWrap := MakeCmdWrap(ecmd, cmdPty)
565-
return &ShellProc{Cmd: cmdWrap, CloseOnce: &sync.Once{}, DoneCh: make(chan any)}, nil
565+
return &ShellProc{Cmd: cmdWrap, ConnName: connName, CloseOnce: &sync.Once{}, DoneCh: make(chan any)}, nil
566566
}
567567

568568
func RunSimpleCmdInPty(ecmd *exec.Cmd, termSize waveobj.TermSize) ([]byte, error) {

0 commit comments

Comments
 (0)