Skip to content

Commit

Permalink
plugin fixes - when no gistid is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
blurymind committed Aug 13, 2024
1 parent 39363ca commit 41558f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
48 changes: 5 additions & 43 deletions src/public/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) )
})
})
}
Expand Down Expand Up @@ -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(
Expand All @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions src/public/plugins/plugin-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export var PluginEditor = function ({
onKeyDown,
onLoad,
setPluginStore,
getVloatilePlugins,
// getVloatilePlugins,
setVloatilePlugin,
setVloatilePlugins,
getGistPluginFiles,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 });
});
Expand Down

0 comments on commit 41558f5

Please sign in to comment.