@@ -5,6 +5,7 @@ import loadPlugin from "./loadPlugin";
55export default async function loadPlugins ( ) {
66 const plugins = await fsOperation ( PLUGIN_DIR ) . lsDir ( ) ;
77 const results = [ ] ;
8+ const failedPlugins = [ ] ;
89
910 if ( plugins . length > 0 ) {
1011 toast ( strings [ "loading plugins" ] ) ;
@@ -20,10 +21,31 @@ export default async function loadPlugins() {
2021 window . log ( "error" , `Failed to load plugin: ${ pluginId } ` ) ;
2122 window . log ( "error" , error ) ;
2223 toast ( `Failed to load plugin: ${ pluginId } ` ) ;
24+ failedPlugins . push ( pluginId ) ;
2325 results . push ( false ) ;
2426 }
2527 } ) ;
2628
2729 await Promise . allSettled ( loadPromises ) ;
30+ if ( failedPlugins . length > 0 ) {
31+ setTimeout ( ( ) => {
32+ cleanupFailedPlugins ( failedPlugins ) . catch ( ( error ) => {
33+ console . error ( "Failed to cleanup plugins:" , error ) ;
34+ } ) ;
35+ } , 1000 ) ;
36+ }
2837 return results . filter ( Boolean ) . length ;
2938}
39+
40+ async function cleanupFailedPlugins ( pluginIds ) {
41+ for ( const pluginId of pluginIds ) {
42+ try {
43+ const pluginDir = Url . join ( PLUGIN_DIR , pluginId ) ;
44+ if ( await fsOperation ( pluginDir ) . exists ( ) ) {
45+ await fsOperation ( pluginDir ) . delete ( ) ;
46+ }
47+ } catch ( error ) {
48+ window . log ( "error" , `Failed to cleanup plugin ${ pluginId } :` , error ) ;
49+ }
50+ }
51+ }
0 commit comments