@@ -44,6 +44,7 @@ import helpers from "utils/helpers";
4444import KeyboardEvent from "utils/keyboardEvent" ;
4545import Url from "utils/Url" ;
4646import constants from "./constants" ;
47+ import { onPluginLoadCallback , onPluginsLoadCompleteCallback , LOADED_PLUGINS } from "lib/loadPlugins" ;
4748
4849export default class Acode {
4950 #modules = { } ;
@@ -62,6 +63,7 @@ export default class Acode {
6263 } ,
6364 } ,
6465 ] ;
66+ #pluginWatchers = { }
6567
6668 constructor ( ) {
6769 const encodingsModule = {
@@ -78,7 +80,7 @@ export default class Acode {
7880 list : themes . list ,
7981 update : themes . update ,
8082 // Deprecated, not supported anymore
81- apply : ( ) => { } ,
83+ apply : ( ) => { } ,
8284 } ;
8385
8486 const sidebarAppsModule = {
@@ -285,21 +287,21 @@ export default class Acode {
285287 */
286288 installPlugin ( pluginId , installerPluginName ) {
287289 return new Promise ( ( resolve , reject ) => {
288- confirm (
289- strings . install ,
290- `Do you want to install plugin '${ pluginId } '${ installerPluginName ? ` requested by ${ installerPluginName } ` : "" } ?` ,
291- )
292- . then ( ( confirmation ) => {
293- if ( ! confirmation ) {
294- reject ( new Error ( "User cancelled installation" ) ) ;
290+ fsOperation ( Url . join ( PLUGIN_DIR , pluginId ) )
291+ . exists ( )
292+ . then ( ( isPluginExists ) => {
293+ if ( isPluginExists ) {
294+ reject ( new Error ( "Plugin already installed" ) ) ;
295295 return ;
296296 }
297297
298- fsOperation ( Url . join ( PLUGIN_DIR , pluginId ) )
299- . exists ( )
300- . then ( ( isPluginExists ) => {
301- if ( isPluginExists ) {
302- reject ( new Error ( "Plugin already installed" ) ) ;
298+ confirm (
299+ strings . install ,
300+ `Do you want to install plugin '${ pluginId } '${ installerPluginName ? ` requested by ${ installerPluginName } ` : "" } ?` ,
301+ )
302+ . then ( ( confirmation ) => {
303+ if ( ! confirmation ) {
304+ reject ( new Error ( "User cancelled installation" ) ) ;
303305 return ;
304306 }
305307
@@ -398,6 +400,31 @@ export default class Acode {
398400 } ) ;
399401 }
400402
403+ [ onPluginLoadCallback ] ( pluginId ) {
404+ if ( this . #pluginWatchers[ pluginId ] ) {
405+ this . #pluginWatchers[ pluginId ] . resolve ( ) ;
406+ delete this . #pluginWatchers[ pluginId ] ;
407+ }
408+ }
409+
410+ [ onPluginsLoadCompleteCallback ] ( ) {
411+ for ( const key in this . #pluginWatchers) {
412+ this . #pluginWatchers[ key ] . reject ( ) ;
413+ }
414+ }
415+
416+ waitForPlugin ( pluginId ) {
417+ return new Promise ( ( resolve , reject ) => {
418+ if ( LOADED_PLUGINS . has ( pluginId ) ) {
419+ return resolve ( true ) ;
420+ }
421+
422+ this . #pluginWatchers[ pluginId ] = {
423+ resolve, reject
424+ }
425+ } ) ;
426+ }
427+
401428 get exitAppMessage ( ) {
402429 const numFiles = editorManager . hasUnsavedFiles ( ) ;
403430 if ( numFiles ) {
0 commit comments