mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
update BlockService to use the new type union feature of tsgen. strongly type the arguments to BlockService.SendCommand
This commit is contained in:
@@ -49,7 +49,7 @@ const Block = ({ blockId, onClose }: BlockProps) => {
|
||||
} else if (blockData.view === "plot") {
|
||||
blockElem = <PlotView />;
|
||||
} else if (blockData.view === "codeedit") {
|
||||
blockElem = <CodeEditView />;
|
||||
blockElem = <CodeEditView text={null} />;
|
||||
}
|
||||
return (
|
||||
<div className="block" ref={blockRef}>
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as WOS from "./wos";
|
||||
// blockservice.BlockService (block)
|
||||
class BlockServiceType {
|
||||
// send command to block
|
||||
SendCommand(blockid: string, command: MetaType): Promise<void> {
|
||||
SendCommand(blockid: string, cmd: BlockCommand): Promise<void> {
|
||||
return WOS.callBackendService("block", "SendCommand", Array.from(arguments))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,10 @@ function handleResize(fitAddon: FitAddon, blockId: string, term: Terminal) {
|
||||
const oldCols = term.cols;
|
||||
fitAddon.fit();
|
||||
if (oldRows !== term.rows || oldCols !== term.cols) {
|
||||
const resizeCommand = { command: "controller:input", termsize: { rows: term.rows, cols: term.cols } };
|
||||
const resizeCommand: BlockInputCommand = {
|
||||
command: "controller:input",
|
||||
termsize: { rows: term.rows, cols: term.cols },
|
||||
};
|
||||
services.BlockService.SendCommand(blockId, resizeCommand);
|
||||
}
|
||||
}
|
||||
@@ -78,17 +81,13 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
|
||||
newTerm.loadAddon(newFitAddon);
|
||||
newTerm.open(connectElemRef.current);
|
||||
newFitAddon.fit();
|
||||
// BlockService.SendCommand(blockId, {
|
||||
// command: "controller:input",
|
||||
// termsize: { rows: newTerm.rows, cols: newTerm.cols },
|
||||
// });
|
||||
services.BlockService.SendCommand(blockId, {
|
||||
command: "controller:input",
|
||||
termsize: { rows: newTerm.rows, cols: newTerm.cols },
|
||||
});
|
||||
newTerm.onData((data) => {
|
||||
const b64data = btoa(data);
|
||||
const inputCmd = { command: "controller:input", blockid: blockId, inputdata64: b64data };
|
||||
const inputCmd: BlockInputCommand = { command: "controller:input", inputdata64: b64data };
|
||||
services.BlockService.SendCommand(blockId, inputCmd);
|
||||
});
|
||||
|
||||
|
||||
Vendored
+31
-1
@@ -14,6 +14,10 @@ declare global {
|
||||
meta: MetaType;
|
||||
};
|
||||
|
||||
type BlockCommand = {
|
||||
command: string;
|
||||
} & ( BlockMessageCommand | BlockInputCommand | BlockSetViewCommand | BlockSetMetaCommand );
|
||||
|
||||
// wstore.BlockDef
|
||||
type BlockDef = {
|
||||
controller?: string;
|
||||
@@ -22,6 +26,32 @@ declare global {
|
||||
meta?: MetaType;
|
||||
};
|
||||
|
||||
// blockcontroller.BlockInputCommand
|
||||
type BlockInputCommand = {
|
||||
command: "controller:input";
|
||||
inputdata64?: string;
|
||||
signame?: string;
|
||||
termsize?: TermSize;
|
||||
};
|
||||
|
||||
// blockcontroller.BlockMessageCommand
|
||||
type BlockMessageCommand = {
|
||||
command: "message";
|
||||
message: string;
|
||||
};
|
||||
|
||||
// blockcontroller.BlockSetMetaCommand
|
||||
type BlockSetMetaCommand = {
|
||||
command: "setmeta";
|
||||
meta: MetaType;
|
||||
};
|
||||
|
||||
// blockcontroller.BlockSetViewCommand
|
||||
type BlockSetViewCommand = {
|
||||
command: "setview";
|
||||
view: string;
|
||||
};
|
||||
|
||||
// wstore.Client
|
||||
type Client = WaveObj & {
|
||||
mainwindowid: string;
|
||||
@@ -62,7 +92,7 @@ declare global {
|
||||
|
||||
type MetaType = {[key: string]: any}
|
||||
|
||||
// servicemeta.MethodMeta
|
||||
// tsgenmeta.MethodMeta
|
||||
type MethodMeta = {
|
||||
Desc: string;
|
||||
ArgNames: string[];
|
||||
|
||||
Reference in New Issue
Block a user