From 41558f509e8a46e42f62574e30f8c4a06da24fe4 Mon Sep 17 00:00:00 2001 From: blurymind Date: Tue, 13 Aug 2024 11:30:50 +0100 Subject: [PATCH] plugin fixes - when no gistid is provided --- src/public/plugins/index.js | 48 +++-------------------------- src/public/plugins/plugin-editor.js | 6 ++-- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/src/public/plugins/index.js b/src/public/plugins/index.js index 0df0d66a..d155a9ec 100644 --- a/src/public/plugins/index.js +++ b/src/public/plugins/index.js @@ -8,7 +8,7 @@ async function importModuleWeb( modulePath, { forceUpdate } = { forceUpdate: false } ) { - if (!script.startsWith("export.module")) return Promise.reject(`${modulePath} Not a module`); + if (!script.startsWith("module.exports")) return Promise.reject(`${modulePath} Not a module`); const { AsyncFunction, cache } = globalThis.__import__ || { AsyncFunction: Object.getPrototypeOf(async function () { }).constructor, @@ -289,8 +289,11 @@ export var Plugins = function (app) { gistPlugins.forEach(item=> { result[item.filename] = item }) + // if gist plugins are fetched, load them, but spread the volatile ones ontop as more recent resolve({...result,...volatilePlugins}) }) + // if no gist plugins are fetched, load the local volatile ones still + .catch(()=> resolve(volatilePlugins) ) }) }) } @@ -381,23 +384,15 @@ export var Plugins = function (app) { window.addEventListener('DOMContentLoaded', e => { registerPlugin(newPlugin); }); - // registerPlugin(newPlugin); }); }; - // const volatileGistPlugins = {}; const loadPluginsFromCacheOrGist = () => { getPluginsList().then(pluginsList=>{ console.log("----->",{pluginsList}) setVloatilePlugins(pluginsList); Object.values(pluginsList).forEach(pluginFile => { - // volatileGistPlugins[pluginFile.filename] = pluginFile; - // setVloatilePlugin( - // pluginFile.filename, - // pluginFile - // ); - loadPluginWithDependencies(pluginFile.content, pluginFile.filename); importModuleWeb(pluginFile.content, pluginFile.filename).then( @@ -411,42 +406,9 @@ export var Plugins = function (app) { ); }) }) - // getGistPluginFiles().then(plugins => - // plugins.forEach(gistFile => { - // console.log({ gistFile, volatilePlugins }); - // if (volatilePlugins && !(gistFile.filename in volatilePlugins)) { - // loadPluginWithDependencies(gistFile.content, gistFile.filename); - - // volatileGistPlugins[gistFile.filename] = gistFile; - // setVloatilePlugin( - // gistFile.filename, - // volatileGistPlugins[gistFile.filename] - // ); - // } else { - // // do not set volatilePlugin from gist if its already in cache - // } - // }) - // ); }; - // const onLoadPluginsFromVolatile = () => { - // Object.values(volatilePlugins).forEach(volatilePlugin => { - // if (volatilePlugin.type === 'builtin') return; // todo for now built in ones dont - // importModuleWeb(volatilePlugin.content, volatilePlugin.name).then( - // importedPlugin => { - // const initializedPlugin = new importedPlugin(pluginApiMethods); - // console.log({ importedPlugin, initializedPlugin }); - // window.addEventListener('DOMContentLoaded', e => { - // registerPlugin(initializedPlugin); - // }); - // } - // ); - // }); - // }; - - // if (app.settings.gistPluginsFile() !== null) { - loadPluginsFromCacheOrGist(); // writes gist data to volatile cache - // } + loadPluginsFromCacheOrGist(); onLoadBuiltInPlugins(); // onLoadPluginsFromVolatile(); }); diff --git a/src/public/plugins/plugin-editor.js b/src/public/plugins/plugin-editor.js index ac59e707..e5805da9 100644 --- a/src/public/plugins/plugin-editor.js +++ b/src/public/plugins/plugin-editor.js @@ -86,7 +86,7 @@ export var PluginEditor = function ({ onKeyDown, onLoad, setPluginStore, - getVloatilePlugins, + // getVloatilePlugins, setVloatilePlugin, setVloatilePlugins, getGistPluginFiles, @@ -154,7 +154,7 @@ export var PluginEditor = function ({ this.onSetEditingFile = () => { const fileName = document.getElementById('edited-plugin-file').value; - getVloatilePlugins().then(volatilePlugins => { + getPluginsList().then(volatilePlugins => { console.log({ volatilePlugins }) this.volatilePlugins = volatilePlugins || {}; let fileContents = this.volatilePlugins[fileName].content; @@ -378,7 +378,7 @@ export var PluginEditor = function ({ onLoad(() => { console.log({ isInDevMode: app.settings.developmentModeEnabled() }); if (!app.settings.developmentModeEnabled()) return; - getVloatilePlugins().then(volatilePlugins => { + getPluginsList().then(volatilePlugins => { this.volatilePlugins = volatilePlugins; console.log({ gotVolatilePlugins: volatilePlugins }); });