added logic to pick up log when its closed via event emotter

This commit is contained in:
phyzical 2022-03-21 19:56:54 +08:00
parent ca02bdefd1
commit 7271f37ec5

@ -18,6 +18,7 @@ import { Theme } from "@mui/material";
import { findRunningScript } from "../../Script/ScriptHelpers"; import { findRunningScript } from "../../Script/ScriptHelpers";
import { Player } from "../../Player"; import { Player } from "../../Player";
import { debounce } from "lodash"; import { debounce } from "lodash";
import { WorkerScriptStartStopEventEmitter } from "../../Netscript/WorkerScriptStartStopEventEmitter";
let layerCounter = 0; let layerCounter = 0;
@ -128,6 +129,23 @@ function LogWindow(props: IProps): React.ReactElement {
setRerender((old) => !old); setRerender((old) => !old);
} }
useEffect(
() =>
WorkerScriptStartStopEventEmitter.subscribe(() => {
setTimeout(() => {
const server = GetServer(script.server);
if (server === null) return;
const exisitingScript = findRunningScript(script.filename, script.args, server);
if (exisitingScript) {
exisitingScript.logs = script.logs.concat(exisitingScript.logs)
setScript(exisitingScript)
}
rerender();
}, 1000)
}),
[],
);
useEffect(() => { useEffect(() => {
updateLayer(); updateLayer();
const id = setInterval(rerender, 1000); const id = setInterval(rerender, 1000);