From c8bec688ebfc9fb1d7e99f6284125e489c136345 Mon Sep 17 00:00:00 2001 From: blurymind Date: Wed, 27 Mar 2024 17:21:52 +0000 Subject: [PATCH] make the plugin repository configurable --- src/index.html | 10 ++++++ src/js/classes/app.js | 5 +++ src/js/classes/settings.js | 12 +++++++ src/public/plugins/index.js | 64 ++++++++++++++++++++----------------- 4 files changed, 61 insertions(+), 30 deletions(-) diff --git a/src/index.html b/src/index.html index 2575e65b..fa5eee80 100755 --- a/src/index.html +++ b/src/index.html @@ -582,6 +582,16 @@

Settings

event: { change: app.workspace.updateArrows }"> + +
+ +
+ +
+ + +
+ diff --git a/src/js/classes/app.js b/src/js/classes/app.js index 1cb255ad..99c8b28e 100644 --- a/src/js/classes/app.js +++ b/src/js/classes/app.js @@ -74,6 +74,11 @@ export var App = function(name, version) { self.mustRefreshNodes.notifySubscribers(); }; + this.setGistPluginsFile = function(gistFile, e) { + const newValue = e ? e.target.value : gistFile; + app.settings.gistPluginsFile(newValue); + }; + this.setFiletypeVersion = function(typeVersion, e) { const filetypeVersion = e ? e.target.value : typeVersion; self.filetypeVersion = filetypeVersion; diff --git a/src/js/classes/settings.js b/src/js/classes/settings.js index 91ab6aae..cbff644f 100644 --- a/src/js/classes/settings.js +++ b/src/js/classes/settings.js @@ -45,6 +45,14 @@ export const Settings = function(app) { .pop() : null, }); + app.setGistPluginsFile( + self.gistPluginsFile() !== null + ? self + .gistPluginsFile() + .split('/') + .pop() + : null + ); }; this.validateGridSize = function() { @@ -87,6 +95,10 @@ export const Settings = function(app) { .observable(storage.getItem('gistFile')) .extend({ persist: 'gistFile' }); + this.gistPluginsFile = ko + .observable(storage.getItem('gistPluginsFile')) + .extend({ persist: 'gistPluginsFile' }); + // Spellcheck enabled this.spellcheckEnabled = ko .observable( diff --git a/src/public/plugins/index.js b/src/public/plugins/index.js index fef08d51..8e38be0d 100644 --- a/src/public/plugins/index.js +++ b/src/public/plugins/index.js @@ -253,7 +253,7 @@ export var Plugins = function(app) { onKeyUp, onKeyDown, onLoad, - } + }; // Todo these are not being cached by the PWA - needs fixing // Todo these should also be optional when building - exclude for build-tiny // plugin initiation @@ -265,37 +265,41 @@ export var Plugins = function(app) { }); // register plugins stored on a gist - todo cache all this - app.gists.get('2ff124dc94f936e8f7d96632f559aecb').then(gist => { - const gistFiles = gist.body.files; - console.log({ gistFiles }); - Object.values(gistFiles).forEach(gistFile => { - if (gistFile.language === 'JavaScript') { - console.log({ gistFile }); - try { - importModuleWeb(gistFile.content, gistFile.filename).then( - importedPlugin => { - const newPlugin = importedPlugin(pluginApiMethods); - newPlugin.name = newPlugin.name || gistFile.filename; - console.log({ newPlugin }, 'loaded from ', gistFile.raw_url); - if ('dependencies' in newPlugin) { - newPlugin.dependencies.forEach(dependency => { - const scriptEle = document.createElement('script'); - scriptEle.setAttribute('src', dependency); - document.body.appendChild(scriptEle); - scriptEle.addEventListener('load', () => { - console.log('File loaded', dependency); - }); + if (app.settings.gistPluginsFile() !== null) { + app.gists.get(app.settings.gistPluginsFile()).then(gist => { + const gistFiles = gist.body.files; + console.log({ gistFiles }); + Object.values(gistFiles).forEach(gistFile => { + if (gistFile.language === 'JavaScript') { + console.log({ gistFile }); + try { + importModuleWeb(gistFile.content, gistFile.filename).then( + importedPlugin => { + const newPlugin = importedPlugin(pluginApiMethods); + newPlugin.name = newPlugin.name || gistFile.filename; + console.log({ newPlugin }, 'loaded from ', gistFile.raw_url); + if ('dependencies' in newPlugin) { + newPlugin.dependencies.forEach(dependency => { + const scriptEle = document.createElement('script'); + scriptEle.setAttribute('src', dependency); + document.body.appendChild(scriptEle); + scriptEle.addEventListener('load', () => { + console.log('File loaded', dependency); + }); - scriptEle.addEventListener('error', ev => { - console.log('Error on loading file', ev); + scriptEle.addEventListener('error', ev => { + console.log('Error on loading file', ev); + }); }); - }); + } + registerPlugin(newPlugin); } - registerPlugin(newPlugin); - } - ); - } catch (e) {console.error(gistFile.filename, "Plugin failed to load", e)} - } + ); + } catch (e) { + console.error(gistFile.filename, 'Plugin failed to load', e); + } + } + }); }); - }); + } };