diff --git a/server/dbSetup.ts b/server/dbSetup.ts index 25ebec8..e2c124a 100644 --- a/server/dbSetup.ts +++ b/server/dbSetup.ts @@ -41,7 +41,6 @@ async function setupDB(db: ModelStatic) { tags: ["Theme", "Simple"], payload: "gruvbox.css", type: "theme", - entryFunc: null }, { package_name: "com.nebula.oled", @@ -53,7 +52,6 @@ async function setupDB(db: ModelStatic) { tags: ["Theme", "Simple", "Sleek"], payload: "oled.css", type: "theme", - entryFunc: null }, { package_name: "com.nebula.lightTheme", @@ -65,7 +63,6 @@ async function setupDB(db: ModelStatic) { tags: ["Theme", "Simple", "Light"], payload: "light.css", type: "theme", - entryFunc: null }, { package_name: "com.nebula.retro", @@ -77,7 +74,6 @@ async function setupDB(db: ModelStatic) { tags: ["Theme", "Simple", "Dark", "Retro"], payload: "retro.css", type: "theme", - entryFunc: null }, { package_name: "com.nebula.darkMode", @@ -89,7 +85,6 @@ async function setupDB(db: ModelStatic) { tags: ["Plugin", "Dark Mode", "Noctura"], payload: "index.js", type: "plugin", - entryFunc: "entryFunc" } ]; const dbItems = await db.findAll(); diff --git a/server/marketplace.ts b/server/marketplace.ts index d525fb7..b309b36 100644 --- a/server/marketplace.ts +++ b/server/marketplace.ts @@ -28,7 +28,6 @@ interface Catalog { background_video: string; payload: string; type: CatalogType; - entryFunc: string; } interface CatalogModel @@ -47,7 +46,6 @@ const catalogAssets = db.define("catalog_assets", { background_video: { type: DataTypes.TEXT, allowNull: true }, payload: { type: DataTypes.TEXT }, type: { type: DataTypes.TEXT }, - entryFunc: { type: DataTypes.STRING } }); function marketplaceAPI(app: FastifyInstance) { @@ -81,7 +79,6 @@ function marketplaceAPI(app: FastifyInstance) { background_video: asset.background_video, payload: asset.payload, type: asset.type, - entryFunc: asset.entryFunc }; return acc; }, {}); @@ -109,7 +106,6 @@ function marketplaceAPI(app: FastifyInstance) { background_video: packageRow.get("background_video"), payload: packageRow.get("payload"), type: packageRow.get("type"), - entryFunc: packageRow.get("entryFunc") }; reply.send(details); } catch (error) { @@ -132,7 +128,6 @@ function marketplaceAPI(app: FastifyInstance) { background_video: string; background_image: string; type: CatalogType; - entryFunc: string; }; }>; interface VerifyStatus { @@ -199,7 +194,6 @@ function marketplaceAPI(app: FastifyInstance) { background_video: request.body.background_video, background_image: request.body.background_image, type: request.body.type as CatalogType, - entryFunc: request.body.entryFunc }; await catalogAssets.create({ package_name: body.package_name, @@ -213,7 +207,6 @@ function marketplaceAPI(app: FastifyInstance) { background_video: body.background_video, background_image: body.background_image, type: body.type, - entryFunc: body.entryFunc }); const assets = fileURLToPath(new URL("../database_assets", import.meta.url)); try { diff --git a/src/utils/settings/marketplace.ts b/src/utils/settings/marketplace.ts index 9b1cab6..d64eb6d 100644 --- a/src/utils/settings/marketplace.ts +++ b/src/utils/settings/marketplace.ts @@ -35,10 +35,15 @@ const marketPlaceSettings = { let plugins = localStorage.getItem(PluginSettings.plugins) as any; plugins ? (plugins = JSON.parse(plugins)) : (plugins = []); //@ts-ignore - if (!plugins.find(({ name }) => name === packageName)) { - plugins.push({name: packageName, src: p.plugin.src, type: p.plugin.type, entryFunc: p.plugin.entryFunc} as unknown as Plugin) + const plugin = plugins.find(({ name }) => name === packageName) as Plugin + if (!plugin) { + plugins.push({name: packageName, src: p.plugin.src, type: p.plugin.type} as unknown as Plugin) localStorage.setItem(PluginSettings.plugins, JSON.stringify(plugins)); } + else if (plugin && plugin.remove) { + plugin.remove = false; + localStorage.setItem(Settings.PluginSettings.plugins, JSON.stringify(plugins)); + } resolve(); } }); @@ -60,9 +65,9 @@ const marketPlaceSettings = { let plugins = localStorage.getItem(PluginSettings.plugins) as any; plugins ? (plugins = JSON.parse(plugins)) : (plugins = []); //@ts-ignore - if (plugins.find(({name}) => name === packageName)) { - const idx = plugins.indexOf(packageName); - plugins.splice(idx, 1); + const plugin = plugins.find(({name}) => name === packageName); + if (plugin) { + plugin.remove = true; localStorage.setItem(PluginSettings.plugins, JSON.stringify(plugins)); } resolve(); @@ -72,15 +77,28 @@ const marketPlaceSettings = { handlePlugins: function(worker: never | ServiceWorkerRegistration) { return new Promise((resolve) => { const plugins = JSON.parse(localStorage.getItem(Settings.PluginSettings.plugins) as string) || []; + if (plugins.length === 0) { + console.log('Plugin length is not greater then 0. Resolving.'); + return resolve(); + } plugins.forEach(async (plugin: Plugin) => { if (plugin.type === "page") { const pluginScript = await fetch(`/packages/${plugin.name}/${plugin.src}`).then((res) => res.text()); const script = eval(pluginScript); const inject = script() as unknown as SWPlugin; - worker.active?.postMessage([{host: inject.host, html: inject.html, injectTo: inject.injectTo}] as SWPlugin[]); + if (plugin.remove) { + const idx = plugins.indexOf(plugin.name); + worker.active?.postMessage([{remove: true, host: inject.host, html: inject.html, injectTo: inject.injectTo}] as SWPlugin[]); + plugins.splice(idx, 1); + localStorage.setItem(Settings.PluginSettings.plugins, JSON.stringify(plugins)); + } + else { + worker.active?.postMessage([{host: inject.host, html: inject.html, injectTo: inject.injectTo}] as SWPlugin[]); + } + //only resolve AFTER we have postMessaged to the SW. + resolve(); } }); - resolve(); }); }, changeTheme: async function ( diff --git a/src/utils/settings/types.ts b/src/utils/settings/types.ts index d14b5db..8a2f0b0 100644 --- a/src/utils/settings/types.ts +++ b/src/utils/settings/types.ts @@ -21,12 +21,13 @@ interface Plugin { name: string; src: string; type: PluginType; - entryFunc: () => unknown | unknown; + remove?: boolean; } interface SWPlugin { host: string; html: string; injectTo: "head" | "body"; + remove?: boolean; } interface Package { theme?: {