Auto reindexing on version upgrades
parent
ca86f75e16
commit
c557253ad1
|
@ -8,6 +8,14 @@ export async function invokeFunction(
|
|||
return syscall("system.invokeFunction", env, name, ...args);
|
||||
}
|
||||
|
||||
export async function invokeCommand(name: string): Promise<any> {
|
||||
return syscall("system.invokeCommand", name);
|
||||
}
|
||||
|
||||
export async function getVersion(): Promise<string> {
|
||||
return syscall("system.getVersion");
|
||||
}
|
||||
|
||||
export async function reloadPlugs() {
|
||||
syscall("system.reloadPlugs");
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ export class System<HookT> extends EventEmitter<SystemEvents<HookT>> {
|
|||
) {
|
||||
await this.unloadAll();
|
||||
for (let manifest of json) {
|
||||
console.log("Loading plug", manifest.name);
|
||||
// console.log("Loading plug", manifest.name);
|
||||
await this.load(manifest, sandboxFactory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,12 @@ functions:
|
|||
command:
|
||||
name: "Page: Delete"
|
||||
|
||||
editorInit:
|
||||
path: "./editor.ts:editorInit"
|
||||
env: client
|
||||
events:
|
||||
- plugs:loaded
|
||||
|
||||
# Backlinks
|
||||
indexLinks:
|
||||
path: "./page.ts:indexLinks"
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import { get, set } from "@silverbulletmd/plugos-silverbullet-syscall";
|
||||
import { flashNotification } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||
import {
|
||||
getVersion,
|
||||
invokeFunction,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/system";
|
||||
|
||||
export async function editorInit() {
|
||||
let currentVersion = await getVersion();
|
||||
console.log("Running version check", currentVersion);
|
||||
let lastVersion = await get("index", "$silverBulletVersion");
|
||||
console.log("Last version", lastVersion);
|
||||
if (lastVersion !== currentVersion) {
|
||||
await flashNotification(
|
||||
"Version update detected, going to reload plugs..."
|
||||
);
|
||||
await set("index", "$spaceIndexed", false);
|
||||
await set("index", "$silverBulletVersion", currentVersion);
|
||||
invokeFunction("client", "updatePlugsCommand");
|
||||
} else {
|
||||
let spaceIndexed = await get("index", "$spaceIndexed");
|
||||
console.log("Space indexed", spaceIndexed);
|
||||
if (!spaceIndexed) {
|
||||
await invokeFunction("client", "reindexSpaceCommand");
|
||||
// Resetting this, because part of the reindex will be to wipe this too
|
||||
await set("index", "$silverBulletVersion", currentVersion);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -189,6 +189,7 @@ async function getBackLinks(pageName: string): Promise<BackLink[]> {
|
|||
export async function reindexCommand() {
|
||||
await flashNotification("Reindexing...");
|
||||
await invokeFunction("server", "reindexSpace");
|
||||
await set("index", "$spaceIndexed", true);
|
||||
await flashNotification("Reindexing done");
|
||||
}
|
||||
|
||||
|
|
|
@ -383,7 +383,8 @@ export class ExpressServer {
|
|||
args
|
||||
);
|
||||
res.status(200);
|
||||
res.send(result);
|
||||
res.header("Content-Type", "application/json");
|
||||
res.send(JSON.stringify(result));
|
||||
} catch (e: any) {
|
||||
res.status(500);
|
||||
return res.send(e.message);
|
||||
|
@ -406,7 +407,8 @@ export class ExpressServer {
|
|||
try {
|
||||
const result = await plug.invoke(name, args);
|
||||
res.status(200);
|
||||
res.send(result);
|
||||
res.header("Content-Type", "application/json");
|
||||
res.send(JSON.stringify(result));
|
||||
} catch (e: any) {
|
||||
res.status(500);
|
||||
// console.log("Error invoking function", e);
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import type { ParseTree } from "@silverbulletmd/common/tree";
|
||||
|
||||
export type AppEvent = "page:click" | "page:complete" | "page:load";
|
||||
export type AppEvent =
|
||||
| "page:click"
|
||||
| "page:complete"
|
||||
| "page:load"
|
||||
| "editor:init"
|
||||
| "plugs:loaded";
|
||||
|
||||
export type ClickEvent = {
|
||||
page: string;
|
||||
|
|
|
@ -234,6 +234,8 @@ export class Editor {
|
|||
await this.pageNavigator.navigate("index");
|
||||
}
|
||||
await this.reloadPlugs();
|
||||
|
||||
await this.dispatchAppEvent("editor:init");
|
||||
}
|
||||
|
||||
async save(immediate: boolean = false): Promise<void> {
|
||||
|
@ -459,11 +461,12 @@ export class Editor {
|
|||
await this.system.unloadAll();
|
||||
console.log("(Re)loading plugs");
|
||||
for (let pageInfo of this.space.listPlugs()) {
|
||||
console.log("Loading plug", pageInfo.name);
|
||||
// console.log("Loading plug", pageInfo.name);
|
||||
let { text } = await this.space.readPage(pageInfo.name);
|
||||
await this.system.load(JSON.parse(text), createIFrameSandbox);
|
||||
}
|
||||
this.rebuildEditorState();
|
||||
await this.dispatchAppEvent("plugs:loaded");
|
||||
}
|
||||
|
||||
rebuildEditorState() {
|
||||
|
@ -725,6 +728,15 @@ export class Editor {
|
|||
);
|
||||
}
|
||||
|
||||
async runCommandByName(name: string) {
|
||||
const cmd = this.viewState.commands.get(name);
|
||||
if (cmd) {
|
||||
await cmd.run();
|
||||
} else {
|
||||
throw new Error(`Command ${name} not found`);
|
||||
}
|
||||
}
|
||||
|
||||
render(container: ReactDOM.Container) {
|
||||
const ViewComponent = this.ViewComponent.bind(this);
|
||||
ReactDOM.render(<ViewComponent />, container);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { SysCallMapping } from "@plugos/plugos/system";
|
||||
import type { Editor } from "../editor";
|
||||
import { version } from "../package.json";
|
||||
|
||||
export function systemSyscalls(editor: Editor): SysCallMapping {
|
||||
return {
|
||||
|
@ -19,6 +20,12 @@ export function systemSyscalls(editor: Editor): SysCallMapping {
|
|||
|
||||
return editor.space.invokeFunction(ctx.plug, env, name, args);
|
||||
},
|
||||
"system.invokeCommand": async (ctx, name: string) => {
|
||||
return editor.runCommandByName(name);
|
||||
},
|
||||
"system.getVersion": async () => {
|
||||
return version;
|
||||
},
|
||||
"system.reloadPlugs": async () => {
|
||||
return editor.reloadPlugs();
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue