From fd72374c7df3d74aa1849d5e438beb3558d01bed Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 4 Mar 2022 12:17:44 +0100 Subject: [PATCH] Plugins -> Plugs --- plugbox/src/runtime.ts | 36 +++++++++--------- webapp/src/editor.tsx | 40 ++++++++++---------- webapp/src/plugbox_browser/browser_system.ts | 4 +- webapp/src/plugbox_sw.ts | 10 ++--- webapp/src/syscalls/ui.browser.ts | 2 +- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/plugbox/src/runtime.ts b/plugbox/src/runtime.ts index 5148d3d..1a68f1d 100644 --- a/plugbox/src/runtime.ts +++ b/plugbox/src/runtime.ts @@ -11,9 +11,9 @@ export class FunctionWorker { private initCallback: any; private invokeResolve?: (result?: any) => void; private invokeReject?: (reason?: any) => void; - private plugin: Plugin; + private plug: Plug; - constructor(plugin: Plugin, pathPrefix: string, name: string) { + constructor(plug: Plug, pathPrefix: string, name: string) { let worker = window.Worker; this.worker = new worker("/function_worker.js"); @@ -29,7 +29,7 @@ export class FunctionWorker { this.inited = new Promise((resolve) => { this.initCallback = resolve; }); - this.plugin = plugin; + this.plug = plug; } async onmessage(evt: MessageEvent) { @@ -40,7 +40,7 @@ export class FunctionWorker { this.initCallback(); break; case "syscall": - let result = await this.plugin.system.syscall(data.name, data.args); + let result = await this.plug.system.syscall(data.name, data.args); this.worker.postMessage({ type: "syscall-response", @@ -76,11 +76,11 @@ export class FunctionWorker { } } -export interface PluginLoader { +export interface PlugLoader { load(name: string, manifest: Manifest): Promise; } -export class Plugin { +export class Plug { pathPrefix: string; system: System; private runningFunctions: Map; @@ -96,7 +96,7 @@ export class Plugin { async load(manifest: Manifest) { this.manifest = manifest; - await this.system.pluginLoader.load(this.name, manifest); + await this.system.plugLoader.load(this.name, manifest); await this.dispatchEvent("load"); } @@ -136,15 +136,15 @@ export class Plugin { } export class System { - protected plugins: Map>; + protected plugs: Map>; protected pathPrefix: string; registeredSyscalls: SysCallMapping; - pluginLoader: PluginLoader; + plugLoader: PlugLoader; - constructor(PluginLoader: PluginLoader, pathPrefix: string) { - this.pluginLoader = PluginLoader; + constructor(plugLoader: PlugLoader, pathPrefix: string) { + this.plugLoader = plugLoader; this.pathPrefix = pathPrefix; - this.plugins = new Map>(); + this.plugs = new Map>(); this.registeredSyscalls = {}; } @@ -167,16 +167,16 @@ export class System { return Promise.resolve(callback(...args)); } - async load(name: string, manifest: Manifest): Promise> { - const plugin = new Plugin(this, this.pathPrefix, name); - await plugin.load(manifest); - this.plugins.set(name, plugin); - return plugin; + async load(name: string, manifest: Manifest): Promise> { + const plug = new Plug(this, this.pathPrefix, name); + await plug.load(manifest); + this.plugs.set(name, plug); + return plug; } async stop(): Promise { return Promise.all( - Array.from(this.plugins.values()).map((plugin) => plugin.stop()) + Array.from(this.plugs.values()).map((plug) => plug.stop()) ); } } diff --git a/webapp/src/editor.tsx b/webapp/src/editor.tsx index 390d3bf..850140c 100644 --- a/webapp/src/editor.tsx +++ b/webapp/src/editor.tsx @@ -38,7 +38,7 @@ import { markdown } from "./markdown"; import { IPageNavigator, PathPageNavigator } from "./navigator"; import customMarkDown from "./parser"; import { BrowserSystem } from "./plugbox_browser/browser_system"; -import { Plugin } from "../../plugbox/src/runtime"; +import { Plug } from "../../plugbox/src/runtime"; import { slashCommandRegexp } from "./types"; import reducer from "./reducer"; @@ -80,7 +80,7 @@ export class Editor implements AppEventDispatcher { openPages: Map; space: Space; editorCommands: Map; - plugins: Plugin[]; + plugs: Plug[]; indexer: Indexer; navigationResolve?: (val: undefined) => void; pageNavigator: IPageNavigator; @@ -88,7 +88,7 @@ export class Editor implements AppEventDispatcher { constructor(space: Space, parent: Element) { this.editorCommands = new Map(); this.openPages = new Map(); - this.plugins = []; + this.plugs = []; this.space = space; this.viewState = initialViewState; this.viewDispatch = () => {}; @@ -104,7 +104,7 @@ export class Editor implements AppEventDispatcher { async init() { await this.loadPageList(); - await this.loadPlugins(); + await this.loadPlugs(); this.focus(); this.pageNavigator.subscribe(async (pageName) => { @@ -123,8 +123,8 @@ export class Editor implements AppEventDispatcher { } } - async loadPlugins() { - const system = new BrowserSystem("/plugin"); + async loadPlugs() { + const system = new BrowserSystem("/plug"); system.registerSyscalls( dbSyscalls, editorSyscalls(this), @@ -133,12 +133,12 @@ export class Editor implements AppEventDispatcher { ); await system.bootServiceWorker(); - console.log("Now loading core plugin"); - let mainPlugin = await system.load("core", coreManifest); - this.plugins.push(mainPlugin); + console.log("Now loading core plug"); + let mainPlug = await system.load("core", coreManifest); + this.plugs.push(mainPlug); this.editorCommands = new Map(); - for (let plugin of this.plugins) { - this.buildCommands(plugin); + for (let plug of this.plugs) { + this.buildCommands(plug); } this.viewDispatch({ type: "update-commands", @@ -146,14 +146,14 @@ export class Editor implements AppEventDispatcher { }); } - private buildCommands(plugin: Plugin) { - const cmds = plugin.manifest!.hooks.commands; + private buildCommands(plug: Plug) { + const cmds = plug.manifest!.hooks.commands; for (let name in cmds) { let cmd = cmds[name]; this.editorCommands.set(name, { command: cmd, run: async (arg): Promise => { - return await plugin.invoke(cmd.invoke, [arg]); + return await plug.invoke(cmd.invoke, [arg]); }, }); } @@ -162,10 +162,10 @@ export class Editor implements AppEventDispatcher { // TODO: Parallelize? async dispatchAppEvent(name: AppEvent, data?: any): Promise { let results: any[] = []; - for (let plugin of this.plugins) { - let pluginResults = await plugin.dispatchEvent(name, data); - if (pluginResults) { - for (let result of pluginResults) { + for (let plug of this.plugs) { + let plugResults = await plug.dispatchEvent(name, data); + if (plugResults) { + for (let result of plugResults) { results.push(result); } } @@ -209,7 +209,7 @@ export class Editor implements AppEventDispatcher { closeBrackets(), autocompletion({ override: [ - this.pluginCompleter.bind(this), + this.plugCompleter.bind(this), this.commandCompleter.bind(this), ], }), @@ -304,7 +304,7 @@ export class Editor implements AppEventDispatcher { }); } - async pluginCompleter( + async plugCompleter( ctx: CompletionContext ): Promise { let allCompletionResults = await this.dispatchAppEvent("editor:complete"); diff --git a/webapp/src/plugbox_browser/browser_system.ts b/webapp/src/plugbox_browser/browser_system.ts index 38067be..f8b0263 100644 --- a/webapp/src/plugbox_browser/browser_system.ts +++ b/webapp/src/plugbox_browser/browser_system.ts @@ -1,8 +1,8 @@ -import { PluginLoader, System } from "../../../plugbox/src/runtime"; +import { PlugLoader, System } from "../../../plugbox/src/runtime"; import { Manifest } from "../../../plugbox/src/types"; import { sleep } from "../util"; -export class BrowserLoader implements PluginLoader { +export class BrowserLoader implements PlugLoader { readonly pathPrefix: string; constructor(pathPrefix: string) { diff --git a/webapp/src/plugbox_sw.ts b/webapp/src/plugbox_sw.ts index 0257aae..ab86100 100644 --- a/webapp/src/plugbox_sw.ts +++ b/webapp/src/plugbox_sw.ts @@ -2,7 +2,7 @@ import { Manifest } from "./types"; import { openDB } from "idb"; -const rootUrl = location.origin + "/plugin"; +const rootUrl = location.origin + "/plug"; // Storing manifests in IndexedDB, y'all const db = openDB("manifests-store", undefined, { @@ -64,13 +64,13 @@ self.addEventListener("fetch", (event: any) => { return await handlePut(req, path); } - let [pluginName, resourceType, functionName] = path.split("/"); + let [plugName, resourceType, functionName] = path.split("/"); - let manifest = await getManifest(pluginName); + let manifest = await getManifest(plugName); if (!manifest) { - // console.log("Ain't got", pluginName); - return new Response(`Plugin not loaded: ${pluginName}`, { + // console.log("Ain't got", plugName); + return new Response(`Plug not loaded: ${plugName}`, { status: 404, }); } diff --git a/webapp/src/syscalls/ui.browser.ts b/webapp/src/syscalls/ui.browser.ts index 40f6a4e..120b022 100644 --- a/webapp/src/syscalls/ui.browser.ts +++ b/webapp/src/syscalls/ui.browser.ts @@ -6,7 +6,7 @@ window.addEventListener("message", async (event) => { let data = messageEvent.data; if (data.type === "iframe_event") { // @ts-ignore - window.mainPlugin.dispatchEvent(data.data.event, data.data.data); + window.mainPlug.dispatchEvent(data.data.event, data.data.data); } });