mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
implement wscommand using type union interface, send resize events there
This commit is contained in:
@@ -157,4 +157,19 @@ function initWS() {
|
||||
globalWS.connectNow("initWS");
|
||||
}
|
||||
|
||||
export { WOS, atoms, getBackendHostPort, getORefSubject, globalStore, globalWS, initWS, useBlockAtom, useBlockCache };
|
||||
function sendWSCommand(command: WSCommandType) {
|
||||
globalWS.pushMessage(command);
|
||||
}
|
||||
|
||||
export {
|
||||
WOS,
|
||||
atoms,
|
||||
getBackendHostPort,
|
||||
getORefSubject,
|
||||
globalStore,
|
||||
globalWS,
|
||||
initWS,
|
||||
sendWSCommand,
|
||||
useBlockAtom,
|
||||
useBlockCache,
|
||||
};
|
||||
|
||||
@@ -283,21 +283,6 @@ function cleanWaveObjectCache() {
|
||||
}
|
||||
}
|
||||
|
||||
// Events.On("waveobj:update", (event: any) => {
|
||||
// const data: WaveObjUpdate[] = event?.data;
|
||||
// if (data == null) {
|
||||
// return;
|
||||
// }
|
||||
// if (!Array.isArray(data)) {
|
||||
// console.log("invalid waveobj:update, not an array", data);
|
||||
// return;
|
||||
// }
|
||||
// if (data.length == 0) {
|
||||
// return;
|
||||
// }
|
||||
// updateWaveObjects(data);
|
||||
// });
|
||||
|
||||
// gets the value of a WaveObject from the cache.
|
||||
// should provide getFn if it is available (e.g. inside of a jotai atom)
|
||||
// otherwise it will use the globalStore.get function
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2024, Command Line Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { getBackendHostPort, getORefSubject, WOS } from "@/store/global";
|
||||
import { WOS, getBackendHostPort, getORefSubject, sendWSCommand } from "@/store/global";
|
||||
import * as services from "@/store/services";
|
||||
import { base64ToArray } from "@/util/util";
|
||||
import { FitAddon } from "@xterm/addon-fit";
|
||||
@@ -49,11 +49,12 @@ function handleResize(fitAddon: FitAddon, blockId: string, term: Terminal) {
|
||||
const oldCols = term.cols;
|
||||
fitAddon.fit();
|
||||
if (oldRows !== term.rows || oldCols !== term.cols) {
|
||||
const resizeCommand: BlockInputCommand = {
|
||||
command: "controller:input",
|
||||
const wsCommand: SetBlockTermSizeWSCommand = {
|
||||
wscommand: "setblocktermsize",
|
||||
blockid: blockId,
|
||||
termsize: { rows: term.rows, cols: term.cols },
|
||||
};
|
||||
services.BlockService.SendCommand(blockId, resizeCommand);
|
||||
sendWSCommand(wsCommand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +82,13 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
|
||||
newTerm.loadAddon(newFitAddon);
|
||||
newTerm.open(connectElemRef.current);
|
||||
newFitAddon.fit();
|
||||
services.BlockService.SendCommand(blockId, {
|
||||
command: "controller:input",
|
||||
// services.BlockService.SendCommand(blockId, {
|
||||
// command: "controller:input",
|
||||
// termsize: { rows: newTerm.rows, cols: newTerm.cols },
|
||||
// });
|
||||
sendWSCommand({
|
||||
wscommand: "setblocktermsize",
|
||||
blockid: blockId,
|
||||
termsize: { rows: newTerm.rows, cols: newTerm.cols },
|
||||
});
|
||||
newTerm.onData((data) => {
|
||||
|
||||
Vendored
+12
-7
@@ -16,7 +16,7 @@ declare global {
|
||||
|
||||
type BlockCommand = {
|
||||
command: string;
|
||||
} & ( BlockMessageCommand | BlockInputCommand | BlockSetViewCommand | BlockSetMetaCommand );
|
||||
} & ( BlockInputCommand | BlockSetViewCommand | BlockSetMetaCommand );
|
||||
|
||||
// wstore.BlockDef
|
||||
type BlockDef = {
|
||||
@@ -34,12 +34,6 @@ declare global {
|
||||
termsize?: TermSize;
|
||||
};
|
||||
|
||||
// blockcontroller.BlockMessageCommand
|
||||
type BlockMessageCommand = {
|
||||
command: "message";
|
||||
message: string;
|
||||
};
|
||||
|
||||
// blockcontroller.BlockSetMetaCommand
|
||||
type BlockSetMetaCommand = {
|
||||
command: "setmeta";
|
||||
@@ -117,6 +111,13 @@ declare global {
|
||||
winsize?: WinSize;
|
||||
};
|
||||
|
||||
// webcmd.SetBlockTermSizeWSCommand
|
||||
type SetBlockTermSizeWSCommand = {
|
||||
wscommand: "setblocktermsize";
|
||||
blockid: string;
|
||||
termsize: TermSize;
|
||||
};
|
||||
|
||||
// wstore.Tab
|
||||
type Tab = WaveObj & {
|
||||
name: string;
|
||||
@@ -137,6 +138,10 @@ declare global {
|
||||
activetabid: string;
|
||||
};
|
||||
|
||||
type WSCommandType = {
|
||||
wscommand: string;
|
||||
} & ( SetBlockTermSizeWSCommand );
|
||||
|
||||
// eventbus.WSEventType
|
||||
type WSEventType = {
|
||||
eventtype: string;
|
||||
|
||||
Reference in New Issue
Block a user