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