@@ -5,69 +5,69 @@ import Url from "utils/Url";
55import actionStack from "./actionStack" ;
66
77export default async function loadPlugin ( pluginId , justInstalled = false ) {
8- const baseUrl = await helpers . toInternalUri ( Url . join ( PLUGIN_DIR , pluginId ) ) ;
9- const cacheFile = Url . join ( CACHE_STORAGE , pluginId ) ;
8+ const baseUrl = await helpers . toInternalUri ( Url . join ( PLUGIN_DIR , pluginId ) ) ;
9+ const cacheFile = Url . join ( CACHE_STORAGE , pluginId ) ;
1010
11- const pluginJson = await fsOperation (
12- Url . join ( PLUGIN_DIR , pluginId , "plugin.json" ) ,
13- ) . readFile ( "json" ) ;
11+ const pluginJson = await fsOperation (
12+ Url . join ( PLUGIN_DIR , pluginId , "plugin.json" ) ,
13+ ) . readFile ( "json" ) ;
1414
15- let mainUrl ;
16- if (
17- await fsOperation ( Url . join ( PLUGIN_DIR , pluginId , pluginJson . main ) ) . exists ( )
18- ) {
19- mainUrl = Url . join ( baseUrl , pluginJson . main ) ;
20- } else {
21- mainUrl = Url . join ( baseUrl , "main.js" ) ;
22- }
15+ let mainUrl ;
16+ if (
17+ await fsOperation ( Url . join ( PLUGIN_DIR , pluginId , pluginJson . main ) ) . exists ( )
18+ ) {
19+ mainUrl = Url . join ( baseUrl , pluginJson . main ) ;
20+ } else {
21+ mainUrl = Url . join ( baseUrl , "main.js" ) ;
22+ }
2323
24- return new Promise ( ( resolve , reject ) => {
25- const $script = < script src = { mainUrl } > </ script > ;
24+ return new Promise ( ( resolve , reject ) => {
25+ const $script = < script src = { mainUrl } > </ script > ;
2626
27- $script . onerror = ( error ) => {
28- reject (
29- new Error (
30- `Failed to load script for plugin ${ pluginId } : ${ error . message || error } ` ,
31- ) ,
32- ) ;
33- } ;
27+ $script . onerror = ( error ) => {
28+ reject (
29+ new Error (
30+ `Failed to load script for plugin ${ pluginId } : ${ error . message || error } ` ,
31+ ) ,
32+ ) ;
33+ } ;
3434
35- $script . onload = async ( ) => {
36- const $page = Page ( "Plugin" ) ;
37- $page . show = ( ) => {
38- actionStack . push ( {
39- id : pluginId ,
40- action : $page . hide ,
41- } ) ;
35+ $script . onload = async ( ) => {
36+ const $page = Page ( "Plugin" ) ;
37+ $page . show = ( ) => {
38+ actionStack . push ( {
39+ id : pluginId ,
40+ action : $page . hide ,
41+ } ) ;
4242
43- app . append ( $page ) ;
44- } ;
43+ app . append ( $page ) ;
44+ } ;
4545
46- $page . onhide = function ( ) {
47- actionStack . remove ( pluginId ) ;
48- } ;
46+ $page . onhide = function ( ) {
47+ actionStack . remove ( pluginId ) ;
48+ } ;
4949
50- try {
51- if ( ! ( await fsOperation ( cacheFile ) . exists ( ) ) ) {
52- await fsOperation ( CACHE_STORAGE ) . createFile ( pluginId ) ;
53- }
50+ try {
51+ if ( ! ( await fsOperation ( cacheFile ) . exists ( ) ) ) {
52+ await fsOperation ( CACHE_STORAGE ) . createFile ( pluginId ) ;
53+ }
5454
55- await acode . initPlugin ( pluginId , baseUrl , $page , {
56- cacheFileUrl : await helpers . toInternalUri ( cacheFile ) ,
57- cacheFile : fsOperation ( cacheFile ) ,
58- firstInit : justInstalled ,
59- ctx : await PluginContext . generate (
60- pluginId ,
61- JSON . stringify ( pluginJson ) ,
62- ) ,
63- } ) ;
55+ await acode . initPlugin ( pluginId , baseUrl , $page , {
56+ cacheFileUrl : await helpers . toInternalUri ( cacheFile ) ,
57+ cacheFile : fsOperation ( cacheFile ) ,
58+ firstInit : justInstalled ,
59+ ctx : await PluginContext . generate (
60+ pluginId ,
61+ JSON . stringify ( pluginJson ) ,
62+ ) ,
63+ } ) ;
6464
65- resolve ( ) ;
66- } catch ( error ) {
67- reject ( error ) ;
68- }
69- } ;
65+ resolve ( ) ;
66+ } catch ( error ) {
67+ reject ( error ) ;
68+ }
69+ } ;
7070
71- document . head . append ( $script ) ;
72- } ) ;
71+ document . head . append ( $script ) ;
72+ } ) ;
7373}
0 commit comments