mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-17 20:51:55 +01:00
Limit User Input Modal to One Window (#1730)
When a connection request is made from a block, only ask for user input in the window that made the request.
This commit is contained in:
parent
309571e288
commit
e555eaa765
@ -37,7 +37,6 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
|
||||
);
|
||||
modalsModel.popModal();
|
||||
}, [responseText, userInputRequest]);
|
||||
console.log("bar");
|
||||
|
||||
const handleSendConfirm = useCallback(
|
||||
(response: boolean) => {
|
||||
@ -64,7 +63,6 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
|
||||
break;
|
||||
}
|
||||
}, [handleSendConfirm, handleSendText, userInputRequest.responsetype]);
|
||||
console.log("baz");
|
||||
|
||||
const handleKeyDown = useCallback(
|
||||
(waveEvent: WaveKeyboardEvent): boolean => {
|
||||
@ -86,7 +84,6 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
|
||||
}
|
||||
return <span className="userinput-text">{userInputRequest.querytext}</span>;
|
||||
}, [userInputRequest.markdown, userInputRequest.querytext]);
|
||||
console.log("foobarbaz");
|
||||
|
||||
const inputBox = useMemo(() => {
|
||||
if (userInputRequest.responsetype === "confirm") {
|
||||
@ -104,7 +101,6 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
|
||||
/>
|
||||
);
|
||||
}, [userInputRequest.responsetype, userInputRequest.publictext, responseText, handleKeyDown, setResponseText]);
|
||||
console.log("mem1");
|
||||
|
||||
const optionalCheckbox = useMemo(() => {
|
||||
if (userInputRequest.checkboxmsg == "") {
|
||||
@ -124,7 +120,6 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
|
||||
</div>
|
||||
);
|
||||
}, []);
|
||||
console.log("mem2");
|
||||
|
||||
useEffect(() => {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
@ -139,7 +134,6 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
|
||||
}
|
||||
return () => clearTimeout(timeout);
|
||||
}, [countdown]);
|
||||
console.log("count");
|
||||
|
||||
const handleNegativeResponse = useCallback(() => {
|
||||
switch (userInputRequest.responsetype) {
|
||||
@ -151,7 +145,6 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
|
||||
break;
|
||||
}
|
||||
}, [userInputRequest.responsetype, handleSendErrResponse, handleSendConfirm]);
|
||||
console.log("before end");
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
@ -168,7 +168,7 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) {
|
||||
};
|
||||
}
|
||||
|
||||
function initGlobalWaveEventSubs() {
|
||||
function initGlobalWaveEventSubs(initOpts: WaveInitOpts) {
|
||||
waveEventSubscribe(
|
||||
{
|
||||
eventType: "waveobj:update",
|
||||
@ -193,6 +193,7 @@ function initGlobalWaveEventSubs() {
|
||||
const data: UserInputRequest = event.data;
|
||||
modalsModel.pushModal("UserInputModal", { ...data });
|
||||
},
|
||||
scope: initOpts.windowId,
|
||||
},
|
||||
{
|
||||
eventType: "blockfile",
|
||||
|
@ -163,7 +163,7 @@ async function initWave(initOpts: WaveInitOpts) {
|
||||
(window as any).globalWS = globalWS;
|
||||
(window as any).TabRpcClient = TabRpcClient;
|
||||
await loadConnStatus();
|
||||
initGlobalWaveEventSubs();
|
||||
initGlobalWaveEventSubs(initOpts);
|
||||
subscribeToConnEvents();
|
||||
|
||||
// ensures client/window/workspace are loaded into the cache before rendering
|
||||
|
@ -16,6 +16,32 @@ import (
|
||||
"github.com/wavetermdev/waveterm/pkg/util/syncbuf"
|
||||
)
|
||||
|
||||
type connContextKeyType struct{}
|
||||
|
||||
var connContextKey connContextKeyType
|
||||
|
||||
type connData struct {
|
||||
BlockId string
|
||||
}
|
||||
|
||||
func ContextWithConnData(ctx context.Context, blockId string) context.Context {
|
||||
if blockId == "" {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, connContextKey, &connData{BlockId: blockId})
|
||||
}
|
||||
|
||||
func GetConnData(ctx context.Context) *connData {
|
||||
if ctx == nil {
|
||||
return nil
|
||||
}
|
||||
dataPtr := ctx.Value(connContextKey)
|
||||
if dataPtr == nil {
|
||||
return nil
|
||||
}
|
||||
return dataPtr.(*connData)
|
||||
}
|
||||
|
||||
type CommandSpec struct {
|
||||
Cmd string
|
||||
Env map[string]string
|
||||
|
@ -11,7 +11,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/wavetermdev/waveterm/pkg/genconn"
|
||||
"github.com/wavetermdev/waveterm/pkg/wps"
|
||||
"github.com/wavetermdev/waveterm/pkg/wstore"
|
||||
)
|
||||
|
||||
var MainUserInputHandler = UserInputHandler{Channels: make(map[string](chan *UserInputResponse), 1)}
|
||||
@ -61,10 +63,11 @@ func (ui *UserInputHandler) unregisterChannel(id string) {
|
||||
delete(ui.Channels, id)
|
||||
}
|
||||
|
||||
func (ui *UserInputHandler) sendRequestToFrontend(request *UserInputRequest) {
|
||||
func (ui *UserInputHandler) sendRequestToFrontend(request *UserInputRequest, windowId string) {
|
||||
wps.Broker.Publish(wps.WaveEvent{
|
||||
Event: wps.Event_UserInput,
|
||||
Data: request,
|
||||
Event: wps.Event_UserInput,
|
||||
Data: request,
|
||||
Scopes: []string{windowId},
|
||||
})
|
||||
}
|
||||
|
||||
@ -74,10 +77,25 @@ func GetUserInput(ctx context.Context, request *UserInputRequest) (*UserInputRes
|
||||
request.RequestId = id
|
||||
deadline, _ := ctx.Deadline()
|
||||
request.TimeoutMs = int(time.Until(deadline).Milliseconds()) - 500
|
||||
MainUserInputHandler.sendRequestToFrontend(request)
|
||||
|
||||
connData := genconn.GetConnData(ctx)
|
||||
// resolve windowId from blockId
|
||||
tabId, err := wstore.DBFindTabForBlockId(ctx, connData.BlockId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unabled to determine tab for route: %w", err)
|
||||
}
|
||||
workspaceId, err := wstore.DBFindWorkspaceForTabId(ctx, tabId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unabled to determine workspace for route: %w", err)
|
||||
}
|
||||
windowId, err := wstore.DBFindWindowForWorkspaceId(ctx, workspaceId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unabled to determine window for route: %w", err)
|
||||
}
|
||||
|
||||
MainUserInputHandler.sendRequestToFrontend(request, windowId)
|
||||
|
||||
var response *UserInputResponse
|
||||
var err error
|
||||
select {
|
||||
case resp := <-uiCh:
|
||||
log.Printf("checking received: %v", resp.RequestId)
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/wavetermdev/waveterm/pkg/blockcontroller"
|
||||
"github.com/wavetermdev/waveterm/pkg/blocklogger"
|
||||
"github.com/wavetermdev/waveterm/pkg/filestore"
|
||||
"github.com/wavetermdev/waveterm/pkg/genconn"
|
||||
"github.com/wavetermdev/waveterm/pkg/panichandler"
|
||||
"github.com/wavetermdev/waveterm/pkg/remote"
|
||||
"github.com/wavetermdev/waveterm/pkg/remote/conncontroller"
|
||||
@ -238,6 +239,7 @@ func (ws *WshServer) ControllerStopCommand(ctx context.Context, blockId string)
|
||||
}
|
||||
|
||||
func (ws *WshServer) ControllerResyncCommand(ctx context.Context, data wshrpc.CommandControllerResyncData) error {
|
||||
ctx = genconn.ContextWithConnData(ctx, data.BlockId)
|
||||
ctx = termCtxWithLogBlockId(ctx, data.BlockId)
|
||||
return blockcontroller.ResyncController(ctx, data.TabId, data.BlockId, data.RtOpts, data.ForceRestart)
|
||||
}
|
||||
@ -627,6 +629,7 @@ func termCtxWithLogBlockId(ctx context.Context, logBlockId string) context.Conte
|
||||
}
|
||||
|
||||
func (ws *WshServer) ConnEnsureCommand(ctx context.Context, data wshrpc.ConnExtData) error {
|
||||
ctx = genconn.ContextWithConnData(ctx, data.LogBlockId)
|
||||
ctx = termCtxWithLogBlockId(ctx, data.LogBlockId)
|
||||
if strings.HasPrefix(data.ConnName, "wsl://") {
|
||||
distroName := strings.TrimPrefix(data.ConnName, "wsl://")
|
||||
@ -656,6 +659,7 @@ func (ws *WshServer) ConnDisconnectCommand(ctx context.Context, connName string)
|
||||
}
|
||||
|
||||
func (ws *WshServer) ConnConnectCommand(ctx context.Context, connRequest wshrpc.ConnRequest) error {
|
||||
ctx = genconn.ContextWithConnData(ctx, connRequest.LogBlockId)
|
||||
ctx = termCtxWithLogBlockId(ctx, connRequest.LogBlockId)
|
||||
connName := connRequest.Host
|
||||
if strings.HasPrefix(connName, "wsl://") {
|
||||
@ -678,6 +682,7 @@ func (ws *WshServer) ConnConnectCommand(ctx context.Context, connRequest wshrpc.
|
||||
}
|
||||
|
||||
func (ws *WshServer) ConnReinstallWshCommand(ctx context.Context, data wshrpc.ConnExtData) error {
|
||||
ctx = genconn.ContextWithConnData(ctx, data.LogBlockId)
|
||||
ctx = termCtxWithLogBlockId(ctx, data.LogBlockId)
|
||||
connName := data.ConnName
|
||||
if strings.HasPrefix(connName, "wsl://") {
|
||||
|
Loading…
Reference in New Issue
Block a user