silverbullet/web/syscalls/system.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

import { SysCallMapping } from "../../plugos/system.ts";
import type { Editor } from "../editor.tsx";
import { CommandDef } from "../hooks/command.ts";
2022-03-25 19:03:06 +08:00
2022-04-27 01:04:36 +08:00
export function systemSyscalls(editor: Editor): SysCallMapping {
2022-03-25 19:03:06 +08:00
return {
2022-10-14 21:11:33 +08:00
"system.invokeFunction": (
ctx,
2022-04-05 23:02:17 +08:00
env: string,
name: string,
...args: any[]
) => {
2022-03-25 19:03:06 +08:00
if (!ctx.plug) {
throw Error("No plug associated with context");
}
2022-04-05 23:02:17 +08:00
if (env === "client") {
return ctx.plug.invoke(name, args);
}
2022-04-27 01:04:36 +08:00
return editor.space.invokeFunction(ctx.plug, env, name, args);
},
2022-10-14 21:11:33 +08:00
"system.invokeCommand": (ctx, name: string) => {
2022-07-11 15:08:22 +08:00
return editor.runCommandByName(name);
},
2022-10-14 21:11:33 +08:00
"system.listCommands": (): { [key: string]: CommandDef } => {
const allCommands: { [key: string]: CommandDef } = {};
2022-09-06 20:36:06 +08:00
for (let [cmd, def] of editor.commandHook.editorCommands) {
allCommands[cmd] = def.command;
}
return allCommands;
},
2022-10-14 21:11:33 +08:00
"system.reloadPlugs": () => {
2022-04-27 01:04:36 +08:00
return editor.reloadPlugs();
2022-03-25 19:03:06 +08:00
},
2022-10-14 21:11:33 +08:00
"sandbox.getServerLogs": (ctx) => {
2022-05-09 20:59:12 +08:00
return editor.space.proxySyscall(ctx.plug, "sandbox.getLogs", []);
},
2022-03-25 19:03:06 +08:00
};
}