mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-31 18:18:02 +01:00
2a5857bc3d
* fix: set golbal ssh config to correct path This adds the missing "etc" directory to the path for the global config file. * chore: update auth mode tooltip This just changes the text to be slightly more accurate to the current behavior. * feat: add box to disable waveshell install modal This hooks in to the existing don't show this again code that pops up when creating a modal. * refactor: remove install modal in remote creation There used to be a modal that popped up while installing a remote that informed the user that waveshell gets installed on their remote. Since we have a new modal that pops up at the time of install, the older modal can be removed. * fix: allow user to cancel ssh dial The new ssh code broke dial for invalid urls since the context did not cancel the dial or any associated user input. This change reconnects the context along with the context for installing waveshell. * style: widen the rconndetail modal The rconndetail modal is currently narrower than the xtermjs element which results in awkward scrolling if a line is long. This change makes the width auto so it can size itself as needed. * add a max-width for safety
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
// Copyright 2024, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Provides a mechanism for the backend to request user input from the frontend.
|
|
package userinput
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/packet"
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/scbus"
|
|
)
|
|
|
|
// An RpcPacket for requesting user input from the client
|
|
type UserInputRequestType struct {
|
|
RequestId string `json:"requestid"`
|
|
QueryText string `json:"querytext"`
|
|
ResponseType string `json:"responsetype"`
|
|
Title string `json:"title"`
|
|
Markdown bool `json:"markdown"`
|
|
TimeoutMs int `json:"timeoutms"`
|
|
CheckBoxMsg string `json:"checkboxmsg"`
|
|
}
|
|
|
|
func (*UserInputRequestType) GetType() string {
|
|
return "userinputrequest"
|
|
}
|
|
|
|
func (req *UserInputRequestType) SetReqId(reqId string) {
|
|
req.RequestId = reqId
|
|
}
|
|
|
|
func (req *UserInputRequestType) SetTimeoutMs(timeoutMs int) {
|
|
req.TimeoutMs = timeoutMs
|
|
}
|
|
|
|
const UserInputResponsePacketStr = "userinputresp"
|
|
|
|
// An RpcResponse for user input requests
|
|
type UserInputResponsePacketType struct {
|
|
Type string `json:"type"`
|
|
RequestId string `json:"requestid"`
|
|
Text string `json:"text,omitempty"`
|
|
Confirm bool `json:"confirm,omitempty"`
|
|
ErrorMsg string `json:"errormsg,omitempty"`
|
|
CheckboxStat bool `json:"checkboxstat,omitempty"`
|
|
}
|
|
|
|
func (*UserInputResponsePacketType) GetType() string {
|
|
return UserInputResponsePacketStr
|
|
}
|
|
|
|
func (pk *UserInputResponsePacketType) GetError() string {
|
|
return pk.ErrorMsg
|
|
}
|
|
|
|
func (pk *UserInputResponsePacketType) SetError(err string) {
|
|
pk.ErrorMsg = err
|
|
}
|
|
|
|
// Send a user input request to the frontend and wait for a response
|
|
func GetUserInput(ctx context.Context, bus *scbus.RpcBus, userInputRequest *UserInputRequestType) (*UserInputResponsePacketType, error) {
|
|
resp, err := scbus.MainRpcBus.DoRpc(ctx, userInputRequest)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if ret, ok := resp.(*UserInputResponsePacketType); !ok {
|
|
return nil, fmt.Errorf("unexpected response type: %v", reflect.TypeOf(resp))
|
|
} else {
|
|
return ret, nil
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
// Register the user input request packet type
|
|
packet.RegisterPacketType(UserInputResponsePacketStr, reflect.TypeOf(UserInputResponsePacketType{}))
|
|
}
|