Auto reindexing on version upgrades
parent
ca86f75e16
commit
c557253ad1
|
@ -8,6 +8,14 @@ export async function invokeFunction(
|
||||||
return syscall("system.invokeFunction", env, name, ...args);
|
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() {
|
export async function reloadPlugs() {
|
||||||
syscall("system.reloadPlugs");
|
syscall("system.reloadPlugs");
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ export class System<HookT> extends EventEmitter<SystemEvents<HookT>> {
|
||||||
) {
|
) {
|
||||||
await this.unloadAll();
|
await this.unloadAll();
|
||||||
for (let manifest of json) {
|
for (let manifest of json) {
|
||||||
console.log("Loading plug", manifest.name);
|
// console.log("Loading plug", manifest.name);
|
||||||
await this.load(manifest, sandboxFactory);
|
await this.load(manifest, sandboxFactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,12 @@ functions:
|
||||||
command:
|
command:
|
||||||
name: "Page: Delete"
|
name: "Page: Delete"
|
||||||
|
|
||||||
|
editorInit:
|
||||||
|
path: "./editor.ts:editorInit"
|
||||||
|
env: client
|
||||||
|
events:
|
||||||
|
- plugs:loaded
|
||||||
|
|
||||||
# Backlinks
|
# Backlinks
|
||||||
indexLinks:
|
indexLinks:
|
||||||
path: "./page.ts: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() {
|
export async function reindexCommand() {
|
||||||
await flashNotification("Reindexing...");
|
await flashNotification("Reindexing...");
|
||||||
await invokeFunction("server", "reindexSpace");
|
await invokeFunction("server", "reindexSpace");
|
||||||
|
await set("index", "$spaceIndexed", true);
|
||||||
await flashNotification("Reindexing done");
|
await flashNotification("Reindexing done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,8 @@ export class ExpressServer {
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
res.status(200);
|
res.status(200);
|
||||||
res.send(result);
|
res.header("Content-Type", "application/json");
|
||||||
|
res.send(JSON.stringify(result));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
res.status(500);
|
res.status(500);
|
||||||
return res.send(e.message);
|
return res.send(e.message);
|
||||||
|
@ -406,7 +407,8 @@ export class ExpressServer {
|
||||||
try {
|
try {
|
||||||
const result = await plug.invoke(name, args);
|
const result = await plug.invoke(name, args);
|
||||||
res.status(200);
|
res.status(200);
|
||||||
res.send(result);
|
res.header("Content-Type", "application/json");
|
||||||
|
res.send(JSON.stringify(result));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
res.status(500);
|
res.status(500);
|
||||||
// console.log("Error invoking function", e);
|
// console.log("Error invoking function", e);
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
import type { ParseTree } from "@silverbulletmd/common/tree";
|
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 = {
|
export type ClickEvent = {
|
||||||
page: string;
|
page: string;
|
||||||
|
|
|
@ -234,6 +234,8 @@ export class Editor {
|
||||||
await this.pageNavigator.navigate("index");
|
await this.pageNavigator.navigate("index");
|
||||||
}
|
}
|
||||||
await this.reloadPlugs();
|
await this.reloadPlugs();
|
||||||
|
|
||||||
|
await this.dispatchAppEvent("editor:init");
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(immediate: boolean = false): Promise<void> {
|
async save(immediate: boolean = false): Promise<void> {
|
||||||
|
@ -459,11 +461,12 @@ export class Editor {
|
||||||
await this.system.unloadAll();
|
await this.system.unloadAll();
|
||||||
console.log("(Re)loading plugs");
|
console.log("(Re)loading plugs");
|
||||||
for (let pageInfo of this.space.listPlugs()) {
|
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);
|
let { text } = await this.space.readPage(pageInfo.name);
|
||||||
await this.system.load(JSON.parse(text), createIFrameSandbox);
|
await this.system.load(JSON.parse(text), createIFrameSandbox);
|
||||||
}
|
}
|
||||||
this.rebuildEditorState();
|
this.rebuildEditorState();
|
||||||
|
await this.dispatchAppEvent("plugs:loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuildEditorState() {
|
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) {
|
render(container: ReactDOM.Container) {
|
||||||
const ViewComponent = this.ViewComponent.bind(this);
|
const ViewComponent = this.ViewComponent.bind(this);
|
||||||
ReactDOM.render(<ViewComponent />, container);
|
ReactDOM.render(<ViewComponent />, container);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { SysCallMapping } from "@plugos/plugos/system";
|
import { SysCallMapping } from "@plugos/plugos/system";
|
||||||
import type { Editor } from "../editor";
|
import type { Editor } from "../editor";
|
||||||
|
import { version } from "../package.json";
|
||||||
|
|
||||||
export function systemSyscalls(editor: Editor): SysCallMapping {
|
export function systemSyscalls(editor: Editor): SysCallMapping {
|
||||||
return {
|
return {
|
||||||
|
@ -19,6 +20,12 @@ export function systemSyscalls(editor: Editor): SysCallMapping {
|
||||||
|
|
||||||
return editor.space.invokeFunction(ctx.plug, env, name, args);
|
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 () => {
|
"system.reloadPlugs": async () => {
|
||||||
return editor.reloadPlugs();
|
return editor.reloadPlugs();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue