Refactor all the things
This commit is contained in:
+2
-1
@@ -1,7 +1,8 @@
|
||||
import { safeRun } from "../common/util.ts";
|
||||
import { Client } from "./client.ts";
|
||||
|
||||
const thinClientMode = window.silverBulletConfig.thinClientMode === "on";
|
||||
const thinClientMode = !!localStorage.getItem("thinClientMode");
|
||||
|
||||
safeRun(async () => {
|
||||
console.log("Booting SilverBullet...");
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@ declare global {
|
||||
// Injected via index.html
|
||||
silverBulletConfig: {
|
||||
spaceFolderPath: string;
|
||||
thinClientMode: "on" | "off";
|
||||
};
|
||||
client: Client;
|
||||
}
|
||||
|
||||
+14
-11
@@ -35,6 +35,7 @@ import { MQHook } from "../plugos/hooks/mq.ts";
|
||||
import { mqSyscalls } from "../plugos/syscalls/mq.dexie.ts";
|
||||
import { indexProxySyscalls } from "./syscalls/index.proxy.ts";
|
||||
import { storeProxySyscalls } from "./syscalls/store.proxy.ts";
|
||||
import { mqProxySyscalls } from "./syscalls/mq.proxy.ts";
|
||||
|
||||
export class ClientSystem {
|
||||
commandHook: CommandHook;
|
||||
@@ -82,7 +83,9 @@ export class ClientSystem {
|
||||
this.system.addHook(this.codeWidgetHook);
|
||||
|
||||
// MQ hook
|
||||
this.system.addHook(new MQHook(this.system, this.mq));
|
||||
if (!this.thinClientMode) {
|
||||
this.system.addHook(new MQHook(this.system, this.mq));
|
||||
}
|
||||
|
||||
// Command hook
|
||||
this.commandHook = new CommandHook();
|
||||
@@ -120,17 +123,17 @@ export class ClientSystem {
|
||||
// console.log("New file list", files);
|
||||
// });
|
||||
|
||||
this.eventHook.addLocalListener("file:changed", (file) => {
|
||||
console.log("File changed", file);
|
||||
});
|
||||
// this.eventHook.addLocalListener("file:changed", (file) => {
|
||||
// console.log("File changed", file);
|
||||
// });
|
||||
|
||||
this.eventHook.addLocalListener("file:created", (file) => {
|
||||
console.log("File created", file);
|
||||
});
|
||||
// this.eventHook.addLocalListener("file:created", (file) => {
|
||||
// console.log("File created", file);
|
||||
// });
|
||||
|
||||
this.eventHook.addLocalListener("file:deleted", (file) => {
|
||||
console.log("File deleted", file);
|
||||
});
|
||||
// this.eventHook.addLocalListener("file:deleted", (file) => {
|
||||
// console.log("File deleted", file);
|
||||
// });
|
||||
|
||||
this.registerSyscalls();
|
||||
}
|
||||
@@ -154,7 +157,7 @@ export class ClientSystem {
|
||||
markdownSyscalls(buildMarkdown(this.mdExtensions)),
|
||||
assetSyscalls(this.system),
|
||||
yamlSyscalls(),
|
||||
mqSyscalls(this.mq),
|
||||
this.thinClientMode ? mqProxySyscalls(this.client) : mqSyscalls(this.mq),
|
||||
storeCalls,
|
||||
this.indexSyscalls,
|
||||
debugSyscalls(),
|
||||
|
||||
+1
-1
@@ -195,7 +195,7 @@ export class MainUI {
|
||||
return;
|
||||
}
|
||||
console.log("Now renaming page to...", newName);
|
||||
await editor.system.system.loadedPlugs.get("core")!.invoke(
|
||||
await editor.system.system.loadedPlugs.get("index")!.invoke(
|
||||
"renamePageCommand",
|
||||
[{ page: newName }],
|
||||
);
|
||||
|
||||
+1
-3
@@ -34,14 +34,12 @@
|
||||
};
|
||||
window.silverBulletConfig = {
|
||||
// These {{VARIABLES}} are replaced by http_server.ts
|
||||
spaceFolderPath: "{{SPACE_PATH}}",
|
||||
thinClientMode: "{{THIN_CLIENT_MODE}}",
|
||||
spaceFolderPath: "{{SPACE_PATH}}"
|
||||
};
|
||||
// But in case these variables aren't replaced by the server, fall back fully static mode (no sync)
|
||||
if (window.silverBulletConfig.spaceFolderPath.includes("{{")) {
|
||||
window.silverBulletConfig = {
|
||||
spaceFolderPath: "",
|
||||
thinClientMode: "off",
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -171,9 +171,20 @@ export function editorSyscalls(editor: Client): SysCallMapping {
|
||||
return editor.confirm(message);
|
||||
},
|
||||
"editor.getUiOption": (_ctx, key: string): any => {
|
||||
if (key === "thinClientMode") {
|
||||
return !!localStorage.getItem("thinClientMode");
|
||||
}
|
||||
return (editor.ui.viewState.uiOptions as any)[key];
|
||||
},
|
||||
"editor.setUiOption": (_ctx, key: string, value: any) => {
|
||||
if (key === "thinClientMode") {
|
||||
if (value) {
|
||||
localStorage.setItem("thinClientMode", "true");
|
||||
} else {
|
||||
localStorage.removeItem("thinClientMode");
|
||||
}
|
||||
return;
|
||||
}
|
||||
editor.ui.viewDispatch({
|
||||
type: "set-ui-option",
|
||||
key,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { Client } from "../client.ts";
|
||||
import { proxySyscalls } from "./util.ts";
|
||||
|
||||
export function mqProxySyscalls(client: Client): SysCallMapping {
|
||||
return proxySyscalls(client, [
|
||||
"mq.send",
|
||||
"mq.batchSend",
|
||||
"mq.ack",
|
||||
"mq.batchAck",
|
||||
"mq.getQueueStats",
|
||||
]);
|
||||
}
|
||||
+7
-11
@@ -10,16 +10,6 @@ export function systemSyscalls(
|
||||
): SysCallMapping {
|
||||
const api: SysCallMapping = {
|
||||
"system.invokeFunction": (
|
||||
ctx,
|
||||
_env: string,
|
||||
name: string,
|
||||
...args: any[]
|
||||
) => {
|
||||
// For backwards compatibility
|
||||
// TODO: Remove at some point
|
||||
return api["system.invoke"](ctx, name, ...args);
|
||||
},
|
||||
"system.invoke": (
|
||||
ctx,
|
||||
name: string,
|
||||
...args: any[]
|
||||
@@ -28,6 +18,12 @@ export function systemSyscalls(
|
||||
throw Error("No plug associated with context");
|
||||
}
|
||||
|
||||
if (name === "server" || name === "client") {
|
||||
// Backwards compatibility mode (previously there was an 'env' argument)
|
||||
name = args[0];
|
||||
args = args.slice(1);
|
||||
}
|
||||
|
||||
let plug: Plug<any> | undefined = ctx.plug;
|
||||
if (name.indexOf(".") !== -1) {
|
||||
// plug name in the name
|
||||
@@ -44,7 +40,7 @@ export function systemSyscalls(
|
||||
}
|
||||
if (functionDef.env && system.env && functionDef.env !== system.env) {
|
||||
// Proxy to another environment
|
||||
return proxySyscall(editor.remoteSpacePrimitives, name, args);
|
||||
return proxySyscall(ctx, editor.remoteSpacePrimitives, name, args);
|
||||
}
|
||||
return plug.invoke(name, args);
|
||||
},
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import { plugCompileCommand } from "../../cmd/plug_compile.ts";
|
||||
import { HttpSpacePrimitives } from "../../common/spaces/http_space_primitives.ts";
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { SyscallContext, SysCallMapping } from "../../plugos/system.ts";
|
||||
import { SyscallResponse } from "../../server/rpc.ts";
|
||||
import { Client } from "../client.ts";
|
||||
|
||||
export function proxySyscalls(client: Client, names: string[]): SysCallMapping {
|
||||
const syscalls: SysCallMapping = {};
|
||||
for (const name of names) {
|
||||
syscalls[name] = (_ctx, ...args: any[]) => {
|
||||
return proxySyscall(client.remoteSpacePrimitives, name, args);
|
||||
syscalls[name] = (ctx, ...args: any[]) => {
|
||||
return proxySyscall(ctx, client.remoteSpacePrimitives, name, args);
|
||||
};
|
||||
}
|
||||
return syscalls;
|
||||
}
|
||||
|
||||
export async function proxySyscall(
|
||||
ctx: SyscallContext,
|
||||
httpSpacePrimitives: HttpSpacePrimitives,
|
||||
name: string,
|
||||
args: any[],
|
||||
@@ -23,6 +25,7 @@ export async function proxySyscall(
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
ctx: ctx.plug.name,
|
||||
operation: "syscall",
|
||||
name,
|
||||
args,
|
||||
|
||||
Reference in New Issue
Block a user