mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-04 18:59:08 +01:00
serialize (w/ actionid) the resize events
This commit is contained in:
parent
aee35f0e01
commit
e6315658e1
@ -46,6 +46,7 @@ type TermWrapOptions = {
|
|||||||
export class TermWrap {
|
export class TermWrap {
|
||||||
blockId: string;
|
blockId: string;
|
||||||
ptyOffset: number;
|
ptyOffset: number;
|
||||||
|
pendingPtyOffset: number;
|
||||||
dataBytesProcessed: number;
|
dataBytesProcessed: number;
|
||||||
terminal: Terminal;
|
terminal: Terminal;
|
||||||
connectElem: HTMLDivElement;
|
connectElem: HTMLDivElement;
|
||||||
@ -56,6 +57,7 @@ export class TermWrap {
|
|||||||
heldData: Uint8Array[];
|
heldData: Uint8Array[];
|
||||||
handleResize_debounced: () => void;
|
handleResize_debounced: () => void;
|
||||||
hasResized: boolean;
|
hasResized: boolean;
|
||||||
|
isLoadingCache: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
blockId: string,
|
blockId: string,
|
||||||
@ -64,6 +66,7 @@ export class TermWrap {
|
|||||||
waveOptions: TermWrapOptions
|
waveOptions: TermWrapOptions
|
||||||
) {
|
) {
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
|
this.isLoadingCache = false;
|
||||||
this.blockId = blockId;
|
this.blockId = blockId;
|
||||||
this.ptyOffset = 0;
|
this.ptyOffset = 0;
|
||||||
this.dataBytesProcessed = 0;
|
this.dataBytesProcessed = 0;
|
||||||
@ -165,11 +168,20 @@ export class TermWrap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleTermData(data: string) {
|
handleTermData(data: string) {
|
||||||
|
if (this.isLoadingCache) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const b64data = util.stringToBase64(data);
|
const b64data = util.stringToBase64(data);
|
||||||
RpcApi.ControllerInputCommand(TabRpcClient, { blockid: this.blockId, inputdata64: b64data });
|
const actionId = util.getNextActionId();
|
||||||
|
RpcApi.ControllerInputCommand(TabRpcClient, {
|
||||||
|
blockid: this.blockId,
|
||||||
|
inputdata64: b64data,
|
||||||
|
feactionid: actionId,
|
||||||
|
pendingptyoffset: this.pendingPtyOffset,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addFocusListener(focusFn: () => void) {
|
addFocusListener(focusFn: () => void) {
|
||||||
@ -198,11 +210,14 @@ export class TermWrap {
|
|||||||
let prtn = new Promise<void>((presolve, _) => {
|
let prtn = new Promise<void>((presolve, _) => {
|
||||||
resolve = presolve;
|
resolve = presolve;
|
||||||
});
|
});
|
||||||
this.terminal.write(data, () => {
|
|
||||||
if (setPtyOffset != null) {
|
if (setPtyOffset != null) {
|
||||||
this.ptyOffset = setPtyOffset;
|
this.pendingPtyOffset = setPtyOffset;
|
||||||
} else {
|
} else {
|
||||||
this.ptyOffset += data.length;
|
this.pendingPtyOffset = this.ptyOffset + data.length;
|
||||||
|
}
|
||||||
|
this.terminal.write(data, () => {
|
||||||
|
this.ptyOffset = this.pendingPtyOffset;
|
||||||
|
if (setPtyOffset == null) {
|
||||||
this.dataBytesProcessed += data.length;
|
this.dataBytesProcessed += data.length;
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
@ -217,6 +232,8 @@ export class TermWrap {
|
|||||||
if (cacheFile != null) {
|
if (cacheFile != null) {
|
||||||
ptyOffset = cacheFile.meta["ptyoffset"] ?? 0;
|
ptyOffset = cacheFile.meta["ptyoffset"] ?? 0;
|
||||||
if (cacheData.byteLength > 0) {
|
if (cacheData.byteLength > 0) {
|
||||||
|
try {
|
||||||
|
this.isLoadingCache = true;
|
||||||
const curTermSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols };
|
const curTermSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols };
|
||||||
const fileTermSize: TermSize = cacheFile.meta["termsize"];
|
const fileTermSize: TermSize = cacheFile.meta["termsize"];
|
||||||
let didResize = false;
|
let didResize = false;
|
||||||
@ -228,10 +245,13 @@ export class TermWrap {
|
|||||||
this.terminal.resize(fileTermSize.cols, fileTermSize.rows);
|
this.terminal.resize(fileTermSize.cols, fileTermSize.rows);
|
||||||
didResize = true;
|
didResize = true;
|
||||||
}
|
}
|
||||||
this.doTerminalWrite(cacheData, ptyOffset);
|
await this.doTerminalWrite(cacheData, ptyOffset);
|
||||||
if (didResize) {
|
if (didResize) {
|
||||||
this.terminal.resize(curTermSize.cols, curTermSize.rows);
|
this.terminal.resize(curTermSize.cols, curTermSize.rows);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
this.isLoadingCache = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { data: mainData, fileInfo: mainFile } = await fetchWaveFile(this.blockId, TermFileName, ptyOffset);
|
const { data: mainData, fileInfo: mainFile } = await fetchWaveFile(this.blockId, TermFileName, ptyOffset);
|
||||||
|
2
frontend/types/gotypes.d.ts
vendored
2
frontend/types/gotypes.d.ts
vendored
@ -116,6 +116,8 @@ declare global {
|
|||||||
blockid: string;
|
blockid: string;
|
||||||
inputdata64?: string;
|
inputdata64?: string;
|
||||||
signame?: string;
|
signame?: string;
|
||||||
|
pendingptyoffset?: number;
|
||||||
|
feactionid?: string;
|
||||||
termsize?: TermSize;
|
termsize?: TermSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ type BlockInputUnion struct {
|
|||||||
InputData []byte `json:"inputdata,omitempty"`
|
InputData []byte `json:"inputdata,omitempty"`
|
||||||
SigName string `json:"signame,omitempty"`
|
SigName string `json:"signame,omitempty"`
|
||||||
TermSize *waveobj.TermSize `json:"termsize,omitempty"`
|
TermSize *waveobj.TermSize `json:"termsize,omitempty"`
|
||||||
|
FeActionId string `json:"feactionid,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockController struct {
|
type BlockController struct {
|
||||||
@ -80,6 +81,8 @@ type BlockController struct {
|
|||||||
ShellProcExitCode int
|
ShellProcExitCode int
|
||||||
RunLock *atomic.Bool
|
RunLock *atomic.Bool
|
||||||
StatusVersion int
|
StatusVersion int
|
||||||
|
ProcessedToOffset int64
|
||||||
|
LastResizeActionId string
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockControllerRuntimeStatus struct {
|
type BlockControllerRuntimeStatus struct {
|
||||||
@ -117,6 +120,16 @@ func (bc *BlockController) getShellProc() *shellexec.ShellProc {
|
|||||||
return bc.ShellProc
|
return bc.ShellProc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bc *BlockController) TestAndSetResizeActionId(actionId string) bool {
|
||||||
|
bc.Lock.Lock()
|
||||||
|
defer bc.Lock.Unlock()
|
||||||
|
if actionId <= bc.LastResizeActionId {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
bc.LastResizeActionId = actionId
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
type RunShellOpts struct {
|
type RunShellOpts struct {
|
||||||
TermSize waveobj.TermSize `json:"termsize,omitempty"`
|
TermSize waveobj.TermSize `json:"termsize,omitempty"`
|
||||||
}
|
}
|
||||||
@ -469,6 +482,8 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
|
|||||||
shellProc.Cmd.Write(ic.InputData)
|
shellProc.Cmd.Write(ic.InputData)
|
||||||
}
|
}
|
||||||
if ic.TermSize != nil {
|
if ic.TermSize != nil {
|
||||||
|
ok := bc.TestAndSetResizeActionId(ic.FeActionId)
|
||||||
|
if ok {
|
||||||
err = setTermSize(ctx, bc.BlockId, *ic.TermSize)
|
err = setTermSize(ctx, bc.BlockId, *ic.TermSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error setting pty size: %v\n", err)
|
log.Printf("error setting pty size: %v\n", err)
|
||||||
@ -479,6 +494,7 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
defer panichandler.PanicHandler("blockcontroller:shellproc-output-loop")
|
defer panichandler.PanicHandler("blockcontroller:shellproc-output-loop")
|
||||||
|
@ -315,6 +315,8 @@ type CommandBlockInputData struct {
|
|||||||
BlockId string `json:"blockid" wshcontext:"BlockId"`
|
BlockId string `json:"blockid" wshcontext:"BlockId"`
|
||||||
InputData64 string `json:"inputdata64,omitempty"`
|
InputData64 string `json:"inputdata64,omitempty"`
|
||||||
SigName string `json:"signame,omitempty"`
|
SigName string `json:"signame,omitempty"`
|
||||||
|
PendingPtyOffset int64 `json:"pendingptyoffset,omitempty"`
|
||||||
|
FeActionId string `json:"feactionid,omitempty"`
|
||||||
TermSize *waveobj.TermSize `json:"termsize,omitempty"`
|
TermSize *waveobj.TermSize `json:"termsize,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,6 +244,7 @@ func (ws *WshServer) ControllerInputCommand(ctx context.Context, data wshrpc.Com
|
|||||||
inputUnion := &blockcontroller.BlockInputUnion{
|
inputUnion := &blockcontroller.BlockInputUnion{
|
||||||
SigName: data.SigName,
|
SigName: data.SigName,
|
||||||
TermSize: data.TermSize,
|
TermSize: data.TermSize,
|
||||||
|
FeActionId: data.FeActionId,
|
||||||
}
|
}
|
||||||
if len(data.InputData64) > 0 {
|
if len(data.InputData64) > 0 {
|
||||||
inputBuf := make([]byte, base64.StdEncoding.DecodedLen(len(data.InputData64)))
|
inputBuf := make([]byte, base64.StdEncoding.DecodedLen(len(data.InputData64)))
|
||||||
|
Loading…
Reference in New Issue
Block a user