@@ -7,9 +7,14 @@ import actionStack from "./actionStack";
77export  default  async  function  loadPlugin ( pluginId ,  justInstalled  =  false )  { 
88	const  baseUrl  =  await  helpers . toInternalUri ( Url . join ( PLUGIN_DIR ,  pluginId ) ) ; 
99	const  cacheFile  =  Url . join ( CACHE_STORAGE ,  pluginId ) ; 
10- 	const  $script  =  < script  src = { Url . join ( baseUrl ,  "main.js" ) } > </ script > ; 
11- 	document . head . append ( $script ) ; 
12- 	return  new  Promise ( ( resolve )  =>  { 
10+ 
11+ 	return  new  Promise ( ( resolve ,  reject )  =>  { 
12+ 		const  $script  =  < script  src = { Url . join ( baseUrl ,  "main.js" ) } > </ script > ; 
13+ 
14+ 		$script . onerror  =  ( error )  =>  { 
15+ 			reject ( new  Error ( `Failed to load script for plugin ${ pluginId }  ` ) ) ; 
16+ 		} ; 
17+ 
1318		$script . onload  =  async  ( )  =>  { 
1419			const  $page  =  Page ( "Plugin" ) ; 
1520			$page . show  =  ( )  =>  { 
@@ -25,19 +30,23 @@ export default async function loadPlugin(pluginId, justInstalled = false) {
2530				actionStack . remove ( pluginId ) ; 
2631			} ; 
2732
28- 			if  ( ! ( await  fsOperation ( cacheFile ) . exists ( ) ) )  { 
29- 				await  fsOperation ( CACHE_STORAGE ) . createFile ( pluginId ) ; 
30- 			} 
3133			try  { 
34+ 				if  ( ! ( await  fsOperation ( cacheFile ) . exists ( ) ) )  { 
35+ 					await  fsOperation ( CACHE_STORAGE ) . createFile ( pluginId ) ; 
36+ 				} 
37+ 
3238				await  acode . initPlugin ( pluginId ,  baseUrl ,  $page ,  { 
3339					cacheFileUrl : await  helpers . toInternalUri ( cacheFile ) , 
3440					cacheFile : fsOperation ( cacheFile ) , 
3541					firstInit : justInstalled , 
3642				} ) ; 
43+ 
44+ 				resolve ( ) ; 
3745			}  catch  ( error )  { 
38- 				toast ( `Error loading plugin  ${ pluginId } :  ${ error . message } ` ) ; 
46+ 				reject ( error ) ; 
3947			} 
40- 			resolve ( ) ; 
4148		} ; 
49+ 
50+ 		document . head . append ( $script ) ; 
4251	} ) ; 
4352} 
0 commit comments