fix: fix unloader

This commit is contained in:
JellyBrick
2023-11-28 11:48:09 +09:00
parent 8f7933c111
commit 75ae9f4fad
3 changed files with 69 additions and 64 deletions

View File

@ -21,6 +21,8 @@ const createContext = (id: string): PreloadContext<PluginConfig> => ({
}); });
export const forceUnloadPreloadPlugin = (id: string) => { export const forceUnloadPreloadPlugin = (id: string) => {
if (!loadedPluginMap[id]) return;
const hasStopped = stopPlugin(id, loadedPluginMap[id], { const hasStopped = stopPlugin(id, loadedPluginMap[id], {
ctx: 'preload', ctx: 'preload',
context: createContext(id), context: createContext(id),
@ -73,7 +75,7 @@ export const loadAllPreloadPlugins = () => {
const pluginConfigs = config.plugins.getPlugins(); const pluginConfigs = config.plugins.getPlugins();
for (const [pluginId, pluginDef] of Object.entries(preloadPlugins)) { for (const [pluginId, pluginDef] of Object.entries(preloadPlugins)) {
const config = deepmerge(pluginDef.config, pluginConfigs[pluginId] ?? {}) ; const config = deepmerge(pluginDef.config ?? { enable: false }, pluginConfigs[pluginId] ?? {}) ;
if (config.enabled) { if (config.enabled) {
forceLoadPreloadPlugin(pluginId); forceLoadPreloadPlugin(pluginId);

View File

@ -145,7 +145,8 @@ export default createPlugin({
]; ];
}, },
async renderer({ getConfig }) { renderer: {
async onPlayerApiReady(_, { getConfig }) {
const config = await getConfig(); const config = await getConfig();
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -218,4 +219,5 @@ export default createPlugin({
{ passive: true }, { passive: true },
); );
}, },
},
}); });

View File

@ -126,10 +126,11 @@ export const stopPlugin = <Config extends PluginConfig>(
if (!def || !def[options.ctx]) return false; if (!def || !def[options.ctx]) return false;
if (typeof def[options.ctx] === 'function') return false; if (typeof def[options.ctx] === 'function') return false;
const stop = def[options.ctx] as PluginLifecycleSimple<Config, unknown>; const defCtx = def[options.ctx] as { stop: PluginLifecycleSimple<Config, unknown> } | undefined;
if (!stop) return null; if (!defCtx?.stop) return null;
try { try {
const stop = defCtx.stop;
const start = performance.now(); const start = performance.now();
stop.bind(def[options.ctx])( stop.bind(def[options.ctx])(
options.context as Config & typeof options.context, options.context as Config & typeof options.context,