[Plugins] Fix plugin loading
This commit is contained in:
parent
89b726cd97
commit
25b90e22d3
2 changed files with 14 additions and 13 deletions
|
@ -13,7 +13,7 @@ import { patchAssets, all, find, getAssetByID, getAssetByName, getAssetIDByName
|
|||
import initSettings from "@ui/settings";
|
||||
import { fixTheme } from "@ui/fixTheme";
|
||||
import { connectToDebugger, patchLogHook, versionHash } from "@lib/debug";
|
||||
import { plugins, fetchPlugin, evalPlugin, stopPlugin, removePlugin, getSettings } from "@lib/plugins";
|
||||
import { plugins, fetchPlugin, evalPlugin, stopPlugin, removePlugin, getSettings, initializePlugins } from "@lib/plugins";
|
||||
import settings from "@lib/settings";
|
||||
import { registerCommand } from "@lib/commands";
|
||||
|
||||
|
@ -66,6 +66,7 @@ async function init() {
|
|||
patchLogHook();
|
||||
patchAssets();
|
||||
fixTheme();
|
||||
initializePlugins();
|
||||
initSettings();
|
||||
} catch (e: Error | any) {
|
||||
erroredOnLoad = true;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Indexable, PluginManifest, Plugin } from "@types";
|
||||
import { navigation } from "@metro/common";
|
||||
import { createStorage, wrapSync } from "@lib/storage";
|
||||
import { awaitSyncWrapper, createStorage, wrapSync } from "@lib/storage";
|
||||
import logger from "@lib/logger";
|
||||
import Subpage from "@ui/settings/components/Subpage";
|
||||
|
||||
|
@ -10,16 +10,7 @@ type EvaledPlugin = {
|
|||
settings: JSX.Element;
|
||||
};
|
||||
|
||||
export const plugins = wrapSync(createStorage<Indexable<Plugin>>("VENDETTA_PLUGINS").then(async function (store) {
|
||||
for (let p of Object.keys(store)) {
|
||||
const plugin: Plugin = store[p];
|
||||
|
||||
if (plugin.update) await fetchPlugin(plugin.id, false);
|
||||
if (plugin.enabled && plugins[p]) await startPlugin(p);
|
||||
}
|
||||
|
||||
return store;
|
||||
}));
|
||||
export const plugins = wrapSync(createStorage<Indexable<Plugin>>("VENDETTA_PLUGINS"));
|
||||
const loadedPlugins: Indexable<EvaledPlugin> = {};
|
||||
|
||||
export async function fetchPlugin(id: string, enabled = true) {
|
||||
|
@ -120,6 +111,15 @@ export function removePlugin(id: string) {
|
|||
delete plugins[id];
|
||||
}
|
||||
|
||||
export async function initializePlugins() {
|
||||
await awaitSyncWrapper(plugins);
|
||||
|
||||
const allIds = Object.keys(plugins);
|
||||
await Promise.allSettled(allIds.map((pl) => fetchPlugin(pl, false)));
|
||||
for (const pl of allIds.filter((pl) => plugins[pl].enabled))
|
||||
startPlugin(pl);
|
||||
}
|
||||
|
||||
export const getSettings = (id: string) => loadedPlugins[id]?.settings;
|
||||
|
||||
export function showSettings(plugin: Plugin) {
|
||||
|
|
Loading…
Reference in a new issue