Page plugin handling (uv.config.inject)
Next up, workerwear for SW plugin handling
This commit is contained in:
parent
fff4d0b286
commit
952337be6e
4 changed files with 27 additions and 20 deletions
|
|
@ -41,7 +41,6 @@ async function setupDB(db: ModelStatic<CatalogModel>) {
|
|||
tags: ["Theme", "Simple"],
|
||||
payload: "gruvbox.css",
|
||||
type: "theme",
|
||||
entryFunc: null
|
||||
},
|
||||
{
|
||||
package_name: "com.nebula.oled",
|
||||
|
|
@ -53,7 +52,6 @@ async function setupDB(db: ModelStatic<CatalogModel>) {
|
|||
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<CatalogModel>) {
|
|||
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<CatalogModel>) {
|
|||
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<CatalogModel>) {
|
|||
tags: ["Plugin", "Dark Mode", "Noctura"],
|
||||
payload: "index.js",
|
||||
type: "plugin",
|
||||
entryFunc: "entryFunc"
|
||||
}
|
||||
];
|
||||
const dbItems = await db.findAll();
|
||||
|
|
|
|||
|
|
@ -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<CatalogModel>("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 {
|
||||
|
|
|
|||
|
|
@ -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<void>((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 (
|
||||
|
|
|
|||
|
|
@ -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?: {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue