(loadOnlyTheme = false)
| 46 | } |
| 47 | |
| 48 | export default async function loadPlugins(loadOnlyTheme = false) { |
| 49 | if (!loadOnlyTheme) { |
| 50 | initialPluginLoadComplete = false; |
| 51 | } |
| 52 | |
| 53 | try { |
| 54 | const plugins = await fsOperation(PLUGIN_DIR).lsDir(); |
| 55 | const results = []; |
| 56 | |
| 57 | if (plugins.length > 0) { |
| 58 | toast(strings["loading plugins"]); |
| 59 | } |
| 60 | |
| 61 | let pluginsToLoad = []; |
| 62 | const currentTheme = settings.value.appTheme; |
| 63 | const enabledMap = settings.value.pluginsDisabled || {}; |
| 64 | |
| 65 | if (loadOnlyTheme) { |
| 66 | // Only load theme plugins matching current theme |
| 67 | pluginsToLoad = plugins.filter((pluginDir) => { |
| 68 | const pluginId = Url.basename(pluginDir.url); |
| 69 | // Skip already loaded and plugins that were previously marked broken |
| 70 | return ( |
| 71 | isThemePlugin(pluginId) && |
| 72 | !LOADED_PLUGINS.has(pluginId) && |
| 73 | enabledMap[pluginId] !== true && |
| 74 | !BROKEN_PLUGINS.has(pluginId) |
| 75 | ); |
| 76 | }); |
| 77 | } else { |
| 78 | // Load non-theme plugins that aren't loaded yet and are enabled |
| 79 | pluginsToLoad = plugins.filter((pluginDir) => { |
| 80 | const pluginId = Url.basename(pluginDir.url); |
| 81 | // Skip theme plugins, already loaded, disabled or previously marked broken |
| 82 | return ( |
| 83 | !isThemePlugin(pluginId) && |
| 84 | !LOADED_PLUGINS.has(pluginId) && |
| 85 | enabledMap[pluginId] !== true && |
| 86 | !BROKEN_PLUGINS.has(pluginId) |
| 87 | ); |
| 88 | }); |
| 89 | } |
| 90 | |
| 91 | const loadPromises = pluginsToLoad.map(async (pluginDir) => { |
| 92 | const pluginId = Url.basename(pluginDir.url); |
| 93 | |
| 94 | if (loadOnlyTheme && currentTheme) { |
| 95 | const pluginIdLower = pluginId.toLowerCase(); |
| 96 | const currentThemeLower = currentTheme.toLowerCase(); |
| 97 | const matchFound = pluginIdLower.includes(currentThemeLower); |
| 98 | // Skip if: |
| 99 | // 1. No match found with current theme AND |
| 100 | // 2. It's not a theme plugin at all |
| 101 | if (!matchFound && !isThemePlugin(pluginId)) { |
| 102 | return; |
| 103 | } |
| 104 | } |
| 105 |
no test coverage detected