@@ -36,6 +36,7 @@ const AUTO_DISABLED_PLUGINS = new Set();
3636const PLUGIN_LOAD_TIMEOUT = 15000 ;
3737const PLUGIN_DISABLE_TIMEOUT = 60000 ;
3838let pluginDisabledUpdateQueue = Promise . resolve ( ) ;
39+ let initialPluginLoadComplete = false ;
3940
4041class PluginLoadTimeoutError extends Error {
4142 constructor ( ) {
@@ -45,70 +46,84 @@ class PluginLoadTimeoutError extends Error {
4546}
4647
4748export default async function loadPlugins ( loadOnlyTheme = false ) {
48- const plugins = await fsOperation ( PLUGIN_DIR ) . lsDir ( ) ;
49- const results = [ ] ;
50-
51- if ( plugins . length > 0 ) {
52- toast ( strings [ "loading plugins" ] ) ;
49+ if ( ! loadOnlyTheme ) {
50+ initialPluginLoadComplete = false ;
5351 }
5452
55- let pluginsToLoad = [ ] ;
56- const currentTheme = settings . value . appTheme ;
57- const enabledMap = settings . value . pluginsDisabled || { } ;
53+ try {
54+ const plugins = await fsOperation ( PLUGIN_DIR ) . lsDir ( ) ;
55+ const results = [ ] ;
5856
59- if ( loadOnlyTheme ) {
60- // Only load theme plugins matching current theme
61- pluginsToLoad = plugins . filter ( ( pluginDir ) => {
62- const pluginId = Url . basename ( pluginDir . url ) ;
63- // Skip already loaded and plugins that were previously marked broken
64- return (
65- isThemePlugin ( pluginId ) &&
66- ! LOADED_PLUGINS . has ( pluginId ) &&
67- enabledMap [ pluginId ] !== true &&
68- ! BROKEN_PLUGINS . has ( pluginId )
69- ) ;
70- } ) ;
71- } else {
72- // Load non-theme plugins that aren't loaded yet and are enabled
73- pluginsToLoad = plugins . filter ( ( pluginDir ) => {
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 ) => {
7492 const pluginId = Url . basename ( pluginDir . url ) ;
75- // Skip theme plugins, already loaded, disabled or previously marked broken
76- return (
77- ! isThemePlugin ( pluginId ) &&
78- ! LOADED_PLUGINS . has ( pluginId ) &&
79- enabledMap [ pluginId ] !== true &&
80- ! BROKEN_PLUGINS . has ( pluginId )
81- ) ;
82- } ) ;
83- }
8493
85- const loadPromises = pluginsToLoad . map ( async ( pluginDir ) => {
86- const pluginId = Url . basename ( pluginDir . url ) ;
87-
88- if ( loadOnlyTheme && currentTheme ) {
89- const pluginIdLower = pluginId . toLowerCase ( ) ;
90- const currentThemeLower = currentTheme . toLowerCase ( ) ;
91- const matchFound = pluginIdLower . includes ( currentThemeLower ) ;
92- // Skip if:
93- // 1. No match found with current theme AND
94- // 2. It's not a theme plugin at all
95- if ( ! matchFound && ! isThemePlugin ( pluginId ) ) {
96- return ;
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+ }
97104 }
98- }
99105
100- try {
101- results . push ( await loadPluginWithTimeout ( pluginId ) ) ;
102- } catch ( error ) {
103- console . error ( `Error loading plugin ${ pluginId } :` , error ) ;
104- results . push ( false ) ;
105- }
106- } ) ;
106+ try {
107+ results . push ( await loadPluginWithTimeout ( pluginId ) ) ;
108+ } catch ( error ) {
109+ console . error ( `Error loading plugin ${ pluginId } :` , error ) ;
110+ results . push ( false ) ;
111+ }
112+ } ) ;
113+
114+ await Promise . allSettled ( loadPromises ) ;
107115
108- await Promise . allSettled ( loadPromises ) ;
116+ acode [ onPluginsLoadCompleteCallback ] ( ) ;
117+ return results . filter ( Boolean ) . length ;
118+ } finally {
119+ if ( ! loadOnlyTheme ) {
120+ initialPluginLoadComplete = true ;
121+ }
122+ }
123+ }
109124
110- acode [ onPluginsLoadCompleteCallback ] ( ) ;
111- return results . filter ( Boolean ) . length ;
125+ export function isInitialPluginLoadComplete ( ) {
126+ return initialPluginLoadComplete ;
112127}
113128
114129export async function loadPluginWithTimeout ( pluginId , justInstalled = false ) {
0 commit comments