mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-01 23:21:59 +01:00
create ref in model, also remove isRunning (#1496)
This commit is contained in:
parent
7df441a389
commit
164c15f1b2
@ -45,7 +45,7 @@ class TermViewModel implements ViewModel {
|
|||||||
viewType: string;
|
viewType: string;
|
||||||
nodeModel: BlockNodeModel;
|
nodeModel: BlockNodeModel;
|
||||||
connected: boolean;
|
connected: boolean;
|
||||||
termRef: React.RefObject<TermWrap>;
|
termRef: React.MutableRefObject<TermWrap> = { current: null };
|
||||||
blockAtom: jotai.Atom<Block>;
|
blockAtom: jotai.Atom<Block>;
|
||||||
termMode: jotai.Atom<string>;
|
termMode: jotai.Atom<string>;
|
||||||
blockId: string;
|
blockId: string;
|
||||||
@ -317,12 +317,6 @@ class TermViewModel implements ViewModel {
|
|||||||
const curStatus = globalStore.get(this.shellProcFullStatus);
|
const curStatus = globalStore.get(this.shellProcFullStatus);
|
||||||
if (curStatus == null || curStatus.version < fullStatus.version) {
|
if (curStatus == null || curStatus.version < fullStatus.version) {
|
||||||
globalStore.set(this.shellProcFullStatus, fullStatus);
|
globalStore.set(this.shellProcFullStatus, fullStatus);
|
||||||
const status = fullStatus?.shellprocstatus ?? "init";
|
|
||||||
if (status == "running") {
|
|
||||||
this.termRef.current?.setIsRunning?.(true);
|
|
||||||
} else {
|
|
||||||
this.termRef.current?.setIsRunning?.(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,8 +718,6 @@ const TermToolbarVDomNode = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
||||||
const viewRef = React.useRef<HTMLDivElement>(null);
|
const viewRef = React.useRef<HTMLDivElement>(null);
|
||||||
const connectElemRef = React.useRef<HTMLDivElement>(null);
|
const connectElemRef = React.useRef<HTMLDivElement>(null);
|
||||||
const termRef = React.useRef<TermWrap>(null);
|
|
||||||
model.termRef = termRef;
|
|
||||||
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
||||||
const termSettingsAtom = useSettingsPrefixAtom("term");
|
const termSettingsAtom = useSettingsPrefixAtom("term");
|
||||||
const termSettings = jotai.useAtomValue(termSettingsAtom);
|
const termSettings = jotai.useAtomValue(termSettingsAtom);
|
||||||
@ -756,7 +748,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
if (termScrollback > 10000) {
|
if (termScrollback > 10000) {
|
||||||
termScrollback = 10000;
|
termScrollback = 10000;
|
||||||
}
|
}
|
||||||
const wasFocused = termRef.current != null && globalStore.get(model.nodeModel.isFocused);
|
const wasFocused = model.termRef.current != null && globalStore.get(model.nodeModel.isFocused);
|
||||||
const termWrap = new TermWrap(
|
const termWrap = new TermWrap(
|
||||||
blockId,
|
blockId,
|
||||||
connectElemRef.current,
|
connectElemRef.current,
|
||||||
@ -775,14 +767,8 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
useWebGl: !termSettings?.["term:disablewebgl"],
|
useWebGl: !termSettings?.["term:disablewebgl"],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const shellProcStatus = globalStore.get(model.shellProcStatus);
|
|
||||||
if (shellProcStatus == "running") {
|
|
||||||
termWrap.setIsRunning(true);
|
|
||||||
} else if (shellProcStatus == "done") {
|
|
||||||
termWrap.setIsRunning(false);
|
|
||||||
}
|
|
||||||
(window as any).term = termWrap;
|
(window as any).term = termWrap;
|
||||||
termRef.current = termWrap;
|
model.termRef.current = termWrap;
|
||||||
const rszObs = new ResizeObserver(() => {
|
const rszObs = new ResizeObserver(() => {
|
||||||
termWrap.handleResize_debounced();
|
termWrap.handleResize_debounced();
|
||||||
});
|
});
|
||||||
@ -810,14 +796,14 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
let stickerConfig = {
|
let stickerConfig = {
|
||||||
charWidth: 8,
|
charWidth: 8,
|
||||||
charHeight: 16,
|
charHeight: 16,
|
||||||
rows: termRef.current?.terminal.rows ?? 24,
|
rows: model.termRef.current?.terminal.rows ?? 24,
|
||||||
cols: termRef.current?.terminal.cols ?? 80,
|
cols: model.termRef.current?.terminal.cols ?? 80,
|
||||||
blockId: blockId,
|
blockId: blockId,
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className={clsx("view-term", "term-mode-" + termMode)} ref={viewRef}>
|
<div className={clsx("view-term", "term-mode-" + termMode)} ref={viewRef}>
|
||||||
<TermResyncHandler blockId={blockId} model={model} />
|
<TermResyncHandler blockId={blockId} model={model} />
|
||||||
<TermThemeUpdater blockId={blockId} model={model} termRef={termRef} />
|
<TermThemeUpdater blockId={blockId} model={model} termRef={model.termRef} />
|
||||||
<TermStickers config={stickerConfig} />
|
<TermStickers config={stickerConfig} />
|
||||||
<TermToolbarVDomNode key="vdom-toolbar" blockId={blockId} model={model} />
|
<TermToolbarVDomNode key="vdom-toolbar" blockId={blockId} model={model} />
|
||||||
<TermVDomNode key="vdom" blockId={blockId} model={model} />
|
<TermVDomNode key="vdom" blockId={blockId} model={model} />
|
||||||
|
@ -55,7 +55,6 @@ export class TermWrap {
|
|||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
heldData: Uint8Array[];
|
heldData: Uint8Array[];
|
||||||
handleResize_debounced: () => void;
|
handleResize_debounced: () => void;
|
||||||
isRunning: boolean;
|
|
||||||
hasResized: boolean;
|
hasResized: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -134,7 +133,6 @@ export class TermWrap {
|
|||||||
this.handleResize_debounced = debounce(50, this.handleResize.bind(this));
|
this.handleResize_debounced = debounce(50, this.handleResize.bind(this));
|
||||||
this.terminal.open(this.connectElem);
|
this.terminal.open(this.connectElem);
|
||||||
this.handleResize();
|
this.handleResize();
|
||||||
this.isRunning = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async initTerminal() {
|
async initTerminal() {
|
||||||
@ -161,10 +159,6 @@ export class TermWrap {
|
|||||||
this.runProcessIdleTimeout();
|
this.runProcessIdleTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsRunning(isRunning: boolean) {
|
|
||||||
this.isRunning = isRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this.terminal.dispose();
|
this.terminal.dispose();
|
||||||
this.mainFileSubject.release();
|
this.mainFileSubject.release();
|
||||||
|
Loading…
Reference in New Issue
Block a user