2022-04-25 08:33:38 +00:00
|
|
|
import { SysCallMapping } from "@plugos/plugos/system";
|
2022-04-26 17:04:36 +00:00
|
|
|
import type { Editor } from "../editor";
|
2022-09-06 12:36:06 +00:00
|
|
|
import { AppCommand, CommandDef } from "../hooks/command";
|
2022-07-11 07:08:22 +00:00
|
|
|
import { version } from "../package.json";
|
2022-03-25 11:03:06 +00:00
|
|
|
|
2022-04-26 17:04:36 +00:00
|
|
|
export function systemSyscalls(editor: Editor): SysCallMapping {
|
2022-03-25 11:03:06 +00:00
|
|
|
return {
|
2022-04-05 15:02:17 +00:00
|
|
|
"system.invokeFunction": async (
|
2022-04-03 16:42:12 +00:00
|
|
|
ctx,
|
2022-04-05 15:02:17 +00:00
|
|
|
env: string,
|
2022-04-03 16:42:12 +00:00
|
|
|
name: string,
|
|
|
|
...args: any[]
|
|
|
|
) => {
|
2022-03-25 11:03:06 +00:00
|
|
|
if (!ctx.plug) {
|
|
|
|
throw Error("No plug associated with context");
|
|
|
|
}
|
2022-04-05 15:02:17 +00:00
|
|
|
|
2022-04-13 12:46:52 +00:00
|
|
|
if (env === "client") {
|
|
|
|
return ctx.plug.invoke(name, args);
|
|
|
|
}
|
|
|
|
|
2022-04-26 17:04:36 +00:00
|
|
|
return editor.space.invokeFunction(ctx.plug, env, name, args);
|
|
|
|
},
|
2022-07-11 07:08:22 +00:00
|
|
|
"system.invokeCommand": async (ctx, name: string) => {
|
|
|
|
return editor.runCommandByName(name);
|
|
|
|
},
|
2022-09-06 12:36:06 +00:00
|
|
|
"system.listCommands": async (
|
|
|
|
ctx
|
|
|
|
): Promise<{ [key: string]: CommandDef }> => {
|
|
|
|
let allCommands: { [key: string]: CommandDef } = {};
|
|
|
|
for (let [cmd, def] of editor.commandHook.editorCommands) {
|
|
|
|
allCommands[cmd] = def.command;
|
|
|
|
}
|
|
|
|
return allCommands;
|
|
|
|
},
|
2022-07-11 07:08:22 +00:00
|
|
|
"system.getVersion": async () => {
|
|
|
|
return version;
|
|
|
|
},
|
2022-04-26 17:04:36 +00:00
|
|
|
"system.reloadPlugs": async () => {
|
|
|
|
return editor.reloadPlugs();
|
2022-03-25 11:03:06 +00:00
|
|
|
},
|
2022-05-09 12:59:12 +00:00
|
|
|
|
|
|
|
"sandbox.getServerLogs": async (ctx) => {
|
|
|
|
return editor.space.proxySyscall(ctx.plug, "sandbox.getLogs", []);
|
|
|
|
},
|
2022-03-25 11:03:06 +00:00
|
|
|
};
|
|
|
|
}
|