mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 19:01:47 +00:00
fix: lifecycle check
edge case: - There may be plugins that don't have a start or stop function
This commit is contained in:
@ -55,18 +55,24 @@ export const forceUnloadMainPlugin = async (
|
||||
ctx: 'backend',
|
||||
context: createContext(id, win),
|
||||
});
|
||||
if (!hasStopped) {
|
||||
if (
|
||||
hasStopped ||
|
||||
(
|
||||
hasStopped === null &&
|
||||
typeof plugin.backend !== 'function' && plugin.backend
|
||||
)
|
||||
) {
|
||||
delete loadedPluginMap[id];
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
resolve();
|
||||
} else {
|
||||
console.log(
|
||||
'[YTMusic]',
|
||||
`Cannot unload "${id}" plugin: no stop function`,
|
||||
`Cannot unload "${id}" plugin`,
|
||||
);
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
delete loadedPluginMap[id];
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
resolve();
|
||||
} catch (err) {
|
||||
console.log('[YTMusic]', `Cannot unload "${id}" plugin: ${String(err)}`);
|
||||
reject(err);
|
||||
@ -87,14 +93,20 @@ export const forceLoadMainPlugin = async (
|
||||
ctx: 'backend',
|
||||
context: createContext(id, win),
|
||||
});
|
||||
if (!hasStarted) {
|
||||
console.log('[YTMusic]', `Cannot load "${id}" plugin`);
|
||||
reject();
|
||||
return;
|
||||
if (
|
||||
hasStarted ||
|
||||
(
|
||||
hasStarted === null &&
|
||||
typeof plugin.backend !== 'function' && plugin.backend
|
||||
)
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
resolve();
|
||||
}
|
||||
|
||||
loadedPluginMap[id] = plugin;
|
||||
resolve();
|
||||
console.log('[YTMusic]', `Cannot load "${id}" plugin`);
|
||||
reject();
|
||||
return;
|
||||
} catch (err) {
|
||||
console.error(
|
||||
'[YTMusic]',
|
||||
|
||||
@ -21,11 +21,18 @@ export const forceUnloadPreloadPlugin = (id: string) => {
|
||||
ctx: 'preload',
|
||||
context: createContext(id),
|
||||
});
|
||||
if (!hasStopped) {
|
||||
console.log('[YTMusic]', `Cannot stop "${id}" plugin`);
|
||||
return;
|
||||
if (
|
||||
hasStopped ||
|
||||
(
|
||||
hasStopped === null &&
|
||||
typeof loadedPluginMap[id].preload !== 'function' && loadedPluginMap[id].preload
|
||||
)
|
||||
) {
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
delete loadedPluginMap[id];
|
||||
} else {
|
||||
console.error('[YTMusic]', `Cannot stop "${id}" plugin`);
|
||||
}
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
};
|
||||
|
||||
export const forceLoadPreloadPlugin = (id: string) => {
|
||||
@ -38,7 +45,15 @@ export const forceLoadPreloadPlugin = (id: string) => {
|
||||
context: createContext(id),
|
||||
});
|
||||
|
||||
if (hasStarted) loadedPluginMap[id] = plugin;
|
||||
if (
|
||||
hasStarted ||
|
||||
(
|
||||
hasStarted === null &&
|
||||
typeof plugin.preload !== 'function' && plugin.preload
|
||||
)
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
}
|
||||
|
||||
console.log('[YTMusic]', `"${id}" plugin is loaded`);
|
||||
} catch (err) {
|
||||
|
||||
@ -40,11 +40,21 @@ export const forceUnloadRendererPlugin = (id: string) => {
|
||||
const plugin = rendererPlugins[id];
|
||||
if (!plugin) return;
|
||||
|
||||
stopPlugin(id, plugin, { ctx: 'renderer', context: createContext(id) });
|
||||
if (plugin?.stylesheets)
|
||||
const hasStopped = stopPlugin(id, plugin, { ctx: 'renderer', context: createContext(id) });
|
||||
if (plugin?.stylesheets) {
|
||||
document.querySelector(`style#plugin-${id}`)?.remove();
|
||||
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
}
|
||||
if (
|
||||
hasStopped ||
|
||||
(
|
||||
hasStopped === null &&
|
||||
typeof plugin?.renderer !== 'function' && plugin?.renderer
|
||||
)
|
||||
) {
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
} else {
|
||||
console.error('[YTMusic]', `Cannot stop "${id}" plugin`);
|
||||
}
|
||||
};
|
||||
|
||||
export const forceLoadRendererPlugin = (id: string) => {
|
||||
@ -56,7 +66,14 @@ export const forceLoadRendererPlugin = (id: string) => {
|
||||
context: createContext(id),
|
||||
});
|
||||
|
||||
if (hasEvaled || plugin?.stylesheets) {
|
||||
if (
|
||||
hasEvaled ||
|
||||
plugin?.stylesheets ||
|
||||
(
|
||||
hasEvaled === null &&
|
||||
typeof plugin?.renderer !== 'function' && plugin?.renderer
|
||||
)
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
|
||||
if (plugin?.stylesheets) {
|
||||
@ -70,7 +87,7 @@ export const forceLoadRendererPlugin = (id: string) => {
|
||||
document.adoptedStyleSheets = [...document.adoptedStyleSheets, ...styleSheetList];
|
||||
}
|
||||
|
||||
if (!hasEvaled) console.log('[YTMusic]', `"${id}" plugin is loaded`);
|
||||
console.log('[YTMusic]', `"${id}" plugin is loaded`);
|
||||
} else {
|
||||
console.log('[YTMusic]', `Cannot initialize "${id}" plugin`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user