Add ns.getRecentScripts()

This commit is contained in:
smolgumball
2022-01-19 00:04:48 -07:00
parent 53727f6222
commit 74e2acfa6f
8 changed files with 184 additions and 51 deletions
+8 -3
View File
@@ -1,19 +1,23 @@
import { RunningScript } from "src/Script/RunningScript";
import { Settings } from "../Settings/Settings";
import { WorkerScript } from "./WorkerScript";
export const recentScripts: RecentScript[] = [];
export function AddRecentScript(workerScript: WorkerScript): void {
if (recentScripts.find((r) => r.pid === workerScript.pid)) return;
const killedTime = new Date();
recentScripts.unshift({
filename: workerScript.name,
args: workerScript.args,
pid: workerScript.pid,
timestamp: new Date(),
timestamp: killedTime,
timestampEpoch: killedTime.getTime(),
runningScript: workerScript.scriptRef,
});
while (recentScripts.length > 50) {
while (recentScripts.length > Settings.MaxRecentScriptsCapacity) {
recentScripts.pop();
}
}
@@ -23,5 +27,6 @@ export interface RecentScript {
args: string[];
pid: number;
timestamp: Date;
timestampEpoch: number;
runningScript: RunningScript;
}