Skip to content

Commit 6abf26a

Browse files
committed
working on FE integration
1 parent be09e31 commit 6abf26a

8 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { RpcApi } from "@/app/store/wshclientapi";
5+
import { TabRpcClient } from "@/app/store/wshrpcutil";
6+
import { isWindows } from "@/util/platformutil";
7+
import { atom, type Atom, type PrimitiveAtom } from "jotai";
8+
import { globalStore } from "./jotaiStore";
9+
10+
class ConnectionsModel {
11+
private static instance: ConnectionsModel;
12+
gitBashPathAtom: PrimitiveAtom<string> = atom("") as PrimitiveAtom<string>;
13+
hasGitBashAtom: Atom<boolean>;
14+
15+
private constructor() {
16+
this.hasGitBashAtom = atom((get) => {
17+
if (!isWindows()) {
18+
return false;
19+
}
20+
const path = get(this.gitBashPathAtom);
21+
return path !== "";
22+
});
23+
this.loadGitBashPath();
24+
}
25+
26+
static getInstance(): ConnectionsModel {
27+
if (!ConnectionsModel.instance) {
28+
ConnectionsModel.instance = new ConnectionsModel();
29+
}
30+
return ConnectionsModel.instance;
31+
}
32+
33+
async loadGitBashPath(rescan: boolean = false): Promise<void> {
34+
if (!isWindows()) {
35+
return;
36+
}
37+
try {
38+
const path = await RpcApi.FindGitBashCommand(TabRpcClient, rescan, { timeout: 2000 });
39+
globalStore.set(this.gitBashPathAtom, path);
40+
} catch (error) {
41+
console.error("Failed to find git bash path:", error);
42+
globalStore.set(this.gitBashPathAtom, "");
43+
}
44+
}
45+
46+
getGitBashPath(): string {
47+
return globalStore.get(this.gitBashPathAtom);
48+
}
49+
}
50+
51+
export { ConnectionsModel };

frontend/app/store/wshclientapi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ class RpcApiType {
282282
return client.wshRpcCall("filewrite", data, opts);
283283
}
284284

285+
// command "findgitbash" [call]
286+
FindGitBashCommand(client: WshClient, data: boolean, opts?: RpcOpts): Promise<string> {
287+
return client.wshRpcCall("findgitbash", data, opts);
288+
}
289+
285290
// command "focuswindow" [call]
286291
FocusWindowCommand(client: WshClient, data: string, opts?: RpcOpts): Promise<void> {
287292
return client.wshRpcCall("focuswindow", data, opts);

frontend/types/gotypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ declare global {
10821082
"term:disablewebgl"?: boolean;
10831083
"term:localshellpath"?: string;
10841084
"term:localshellopts"?: string[];
1085+
"term:gitbashpath"?: string;
10851086
"term:scrollback"?: number;
10861087
"term:copyonselect"?: boolean;
10871088
"term:transparency"?: number;

pkg/wconfig/metaconsts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
ConfigKey_TermDisableWebGl = "term:disablewebgl"
4141
ConfigKey_TermLocalShellPath = "term:localshellpath"
4242
ConfigKey_TermLocalShellOpts = "term:localshellopts"
43+
ConfigKey_TermGitBashPath = "term:gitbashpath"
4344
ConfigKey_TermScrollback = "term:scrollback"
4445
ConfigKey_TermCopyOnSelect = "term:copyonselect"
4546
ConfigKey_TermTransparency = "term:transparency"

pkg/wshrpc/wshclient/wshclient.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ func FileWriteCommand(w *wshutil.WshRpc, data wshrpc.FileData, opts *wshrpc.RpcO
344344
return err
345345
}
346346

347+
// command "findgitbash", wshserver.FindGitBashCommand
348+
func FindGitBashCommand(w *wshutil.WshRpc, data bool, opts *wshrpc.RpcOpts) (string, error) {
349+
resp, err := sendRpcRequestCallHelper[string](w, "findgitbash", data, opts)
350+
return resp, err
351+
}
352+
347353
// command "focuswindow", wshserver.FocusWindowCommand
348354
func FocusWindowCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts) error {
349355
_, err := sendRpcRequestCallHelper[any](w, "focuswindow", data, opts)

pkg/wshrpc/wshrpctypes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const (
129129
Command_WslDefaultDistro = "wsldefaultdistro"
130130
Command_DismissWshFail = "dismisswshfail"
131131
Command_ConnUpdateWsh = "updatewsh"
132+
Command_FindGitBash = "findgitbash"
132133

133134
Command_WorkspaceList = "workspacelist"
134135

@@ -274,6 +275,7 @@ type WshRpcInterface interface {
274275
WslDefaultDistroCommand(ctx context.Context) (string, error)
275276
DismissWshFailCommand(ctx context.Context, connName string) error
276277
ConnUpdateWshCommand(ctx context.Context, remoteInfo RemoteInfo) (bool, error)
278+
FindGitBashCommand(ctx context.Context, rescan bool) (string, error)
277279

278280
// eventrecv is special, it's handled internally by WshRpc with EventListener
279281
EventRecvCommand(ctx context.Context, data wps.WaveEvent) error

pkg/wshrpc/wshserver/wshserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ func (ws *WshServer) DismissWshFailCommand(ctx context.Context, connName string)
826826
return nil
827827
}
828828

829+
func (ws *WshServer) FindGitBashCommand(ctx context.Context, rescan bool) (string, error) {
830+
fullConfig := wconfig.GetWatcher().GetFullConfig()
831+
return shellutil.FindGitBash(&fullConfig, rescan), nil
832+
}
833+
829834
func (ws *WshServer) BlockInfoCommand(ctx context.Context, blockId string) (*wshrpc.BlockInfoData, error) {
830835
blockData, err := wstore.DBMustGet[*waveobj.Block](ctx, blockId)
831836
if err != nil {

schema/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
},
9999
"type": "array"
100100
},
101+
"term:gitbashpath": {
102+
"type": "string"
103+
},
101104
"term:scrollback": {
102105
"type": "integer"
103106
},

0 commit comments

Comments
 (0)