Fix some nasty bug
parent
859657f8b8
commit
4d201efdbb
|
@ -44,6 +44,7 @@ class IFrameWrapper implements WorkerLike {
|
|||
}
|
||||
|
||||
terminate() {
|
||||
console.log("Terminating iframe sandbox");
|
||||
window.removeEventListener("message", this.messageListener);
|
||||
return this.iframe.remove();
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ export class System<HookT> extends EventEmitter<SystemEvents<HookT>> {
|
|||
sandboxFactory: SandboxFactory<HookT>
|
||||
): Promise<Plug<HookT>> {
|
||||
if (this.plugs.has(name)) {
|
||||
console.log("Unloading", name);
|
||||
await this.unload(name);
|
||||
}
|
||||
// Validate
|
||||
|
|
|
@ -30,7 +30,8 @@ export async function updateMaterializedQueriesCommand() {
|
|||
"updateMaterializedQueriesOnPage",
|
||||
await syscall("editor.getCurrentPage")
|
||||
);
|
||||
syscall("editor.flashNotification", "Updated materialized queries");
|
||||
await syscall("editor.reloadPage");
|
||||
await syscall("editor.flashNotification", "Updated materialized queries");
|
||||
}
|
||||
|
||||
// Called from client, running on server
|
||||
|
@ -59,6 +60,21 @@ export async function updateMaterializedQueriesOnPage(pageName: string) {
|
|||
}
|
||||
}
|
||||
return `${startQuery}\n${results.join("\n")}\n${endQuery}`;
|
||||
case "link":
|
||||
let uniqueLinks = new Set<string>();
|
||||
for (let {key, page, value: name} of await syscall(
|
||||
"index.scanPrefixGlobal",
|
||||
`pl:${pageName}:`
|
||||
)) {
|
||||
let [, pos] = key.split(":");
|
||||
if (!filter || (filter && name.includes(filter))) {
|
||||
uniqueLinks.add(name);
|
||||
}
|
||||
}
|
||||
for (const uniqueResult of uniqueLinks) {
|
||||
results.push(`* [[${uniqueResult}]]`);
|
||||
}
|
||||
return `${startQuery}\n${results.sort().join("\n")}\n${endQuery}`;
|
||||
case "item":
|
||||
for (let {
|
||||
key,
|
||||
|
|
|
@ -12,6 +12,8 @@ import spaceSyscalls from "./syscalls/space";
|
|||
import { eventSyscalls } from "../plugos/syscalls/event";
|
||||
import { pageIndexSyscalls } from "./syscalls";
|
||||
import knex, { Knex } from "knex";
|
||||
import shellSyscalls from "../plugos/syscalls/shell.node";
|
||||
import { NodeCronHook } from "../plugos/hooks/node_cron";
|
||||
|
||||
export class ExpressServer {
|
||||
app: Express;
|
||||
|
@ -47,6 +49,10 @@ export class ExpressServer {
|
|||
},
|
||||
useNullAsDefault: true,
|
||||
});
|
||||
|
||||
system.registerSyscalls("shell", ["shell"], shellSyscalls(rootPath));
|
||||
system.addHook(new NodeCronHook());
|
||||
|
||||
system.registerSyscalls("index", [], pageIndexSyscalls(this.db));
|
||||
system.registerSyscalls("space", [], spaceSyscalls(this.storage));
|
||||
system.registerSyscalls("event", [], eventSyscalls(this.eventHook));
|
||||
|
@ -69,7 +75,7 @@ export class ExpressServer {
|
|||
.route(/\/(.+)/)
|
||||
.get(async (req, res) => {
|
||||
let pageName = req.params[0];
|
||||
console.log("Getting", pageName);
|
||||
// console.log("Getting", pageName);
|
||||
try {
|
||||
let pageData = await this.storage.readPage(pageName);
|
||||
res.status(200);
|
||||
|
@ -80,7 +86,7 @@ export class ExpressServer {
|
|||
res.status(200);
|
||||
res.send("");
|
||||
}
|
||||
})
|
||||
};)
|
||||
.put(bodyParser.text({ type: "*/*" }), async (req, res) => {
|
||||
let pageName = req.params[0];
|
||||
console.log("Saving", pageName);
|
|
@ -5,10 +5,8 @@ import http from "http";
|
|||
import yargs from "yargs";
|
||||
import {hideBin} from "yargs/helpers";
|
||||
import {SilverBulletHooks} from "../common/manifest";
|
||||
import {ExpressServer} from "./express_server";
|
||||
import {ExpressServer} from "./api_server";
|
||||
import {DiskPlugLoader} from "../plugos/plug_loader";
|
||||
import {NodeCronHook} from "../plugos/hooks/node_cron";
|
||||
import shellSyscalls from "../plugos/syscalls/shell.node";
|
||||
import {System} from "../plugos/system";
|
||||
|
||||
let args = yargs(hideBin(process.argv))
|
||||
|
@ -44,8 +42,6 @@ expressServer
|
|||
);
|
||||
await plugLoader.loadPlugs();
|
||||
plugLoader.watcher();
|
||||
system.registerSyscalls("shell", ["shell"], shellSyscalls(pagesPath));
|
||||
system.addHook(new NodeCronHook());
|
||||
server.listen(port, () => {
|
||||
console.log(`Server listening on port ${port}`);
|
||||
});
|
||||
|
|
|
@ -36,7 +36,7 @@ import indexerSyscalls from "./syscalls/indexer";
|
|||
import spaceSyscalls from "./syscalls/space";
|
||||
import { Action, AppViewState, initialViewState } from "./types";
|
||||
import { SilverBulletHooks } from "../common/manifest";
|
||||
import { safeRun } from "./util";
|
||||
import { safeRun, throttle } from "./util";
|
||||
import { System } from "../plugos/system";
|
||||
import { EventHook } from "../plugos/hooks/event";
|
||||
import { systemSyscalls } from "./syscalls/system";
|
||||
|
@ -132,6 +132,10 @@ export class Editor implements AppEventDispatcher {
|
|||
}
|
||||
});
|
||||
|
||||
let throttledRebuildEditorState = throttle(() => {
|
||||
this.rebuildEditorState();
|
||||
}, 100);
|
||||
|
||||
this.space.on({
|
||||
pageCreated: (meta) => {
|
||||
console.log("Page created", meta);
|
||||
|
@ -156,12 +160,14 @@ export class Editor implements AppEventDispatcher {
|
|||
safeRun(async () => {
|
||||
console.log("Plug load", plugName);
|
||||
await this.system.load(plugName, plug, createIFrameSandbox);
|
||||
throttledRebuildEditorState();
|
||||
});
|
||||
},
|
||||
plugUnloaded: (plugName) => {
|
||||
safeRun(async () => {
|
||||
console.log("Plug unload", plugName);
|
||||
await this.system.unload(plugName);
|
||||
throttledRebuildEditorState();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
@ -364,6 +370,15 @@ export class Editor implements AppEventDispatcher {
|
|||
});
|
||||
}
|
||||
|
||||
rebuildEditorState() {
|
||||
const editorView = this.editorView;
|
||||
if (editorView && this.currentPage) {
|
||||
editorView.setState(
|
||||
this.createEditorState(this.currentPage, editorView.state.sliceDoc())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
reloadPage() {
|
||||
console.log("Reloading page");
|
||||
safeRun(async () => {
|
||||
|
|
|
@ -185,7 +185,6 @@ export class Space extends EventEmitter<SpaceEvents> {
|
|||
name: string,
|
||||
args: any[]
|
||||
): Promise<any> {
|
||||
console.log("Making a remote syscall", name, args);
|
||||
let req = await fetch(`${this.plugUrl}/${plug.name}/syscall/${name}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -204,7 +203,6 @@ export class Space extends EventEmitter<SpaceEvents> {
|
|||
}
|
||||
|
||||
async remoteInvoke(plug: Plug<any>, name: string, args: any[]): Promise<any> {
|
||||
console.log("Making a remote syscall", name, JSON.stringify(args));
|
||||
let req = await fetch(`${this.plugUrl}/${plug.name}/function/${name}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
|
@ -39,6 +39,9 @@ export default (editor: Editor): SysCallMapping => ({
|
|||
navigate: async (ctx, name: string, pos: number) => {
|
||||
await editor.navigate(name, pos);
|
||||
},
|
||||
reloadPage: async (ctx) => {
|
||||
await editor.reloadPage();
|
||||
},
|
||||
openUrl: async (ctx, url: string) => {
|
||||
window.open(url, "_blank")!.focus();
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue