@@ -21,6 +21,7 @@ import software.aws.toolkits.core.utils.warn
2121import  software.aws.toolkits.jetbrains.AwsToolkit.TOOLKIT_PLUGIN_ID 
2222import  software.aws.toolkits.jetbrains.core.plugin.PluginUpdateManager 
2323import  software.aws.toolkits.resources.message 
24+ import  javax.swing.SwingUtilities 
2425
2526class  PluginVersionChecker  : ApplicationInitializedListener  {
2627    override  suspend  fun  execute (asyncScope :  CoroutineScope ) {
@@ -51,19 +52,14 @@ class PluginVersionChecker : ApplicationInitializedListener {
5152
5253        //  defensively disable the old toolkit if we couldn't update it because we might deadlock during project open
5354        val  toolkit =  mismatch.firstOrNull { it.id ==  TOOLKIT_PLUGIN_ID  &&  it.version?.startsWith(" 2." ==  true  }
54-         val  shouldDisableToolkit =  (toolkit !=  null  &&  updated.none { it ==  toolkit })
55-         if  (shouldDisableToolkit) {
56-             LOG .info { " Attempting to disable aws.toolkit due to known incompatibility" 
57-             val  descriptor =  toolkit?.descriptor as ?  IdeaPluginDescriptor 
58- 
59-             descriptor?.let  {
60-                 PluginEnabler .getInstance().disable(listOf (descriptor))
61-             } ? :  LOG .warn { " Expected toolkit descriptor to be IdeaPluginDescriptor, but was ${toolkit?.descriptor} " 
62-         }
6355
64-         if  (shouldDisableToolkit ||  updated.isNotEmpty()) {
56+         if  (shouldDisableToolkit(toolkit, updated)  ||  updated.isNotEmpty()) {
6557            LOG .info { " Restarting due to forced update of plugins" 
66-             ApplicationManagerEx .getApplicationEx().restart(true )
58+ 
59+             //  IDE invokeLater is not initialized yet
60+             SwingUtilities .invokeAndWait {
61+                 ApplicationManagerEx .getApplicationEx().restart(true )
62+             }
6763            return 
6864        }
6965
@@ -82,7 +78,7 @@ class PluginVersionChecker : ApplicationInitializedListener {
8278                        coreDescriptor?.let  { descriptor ->  PluginUpdateManager .updatePlugin(descriptor, EmptyProgressIndicator ()) }
8379                    }
8480
85-                     PluginEnabler .getInstance() .disable(
81+                     PluginEnabler .HEADLESS .disable(
8682                        AwsToolkit .PLUGINS_INFO .values.mapNotNull {
8783                            val  descriptor =  it.descriptor as ?  IdeaPluginDescriptor 
8884                            if  (descriptor !=  null  &&  descriptor !=  core.descriptor) {
@@ -97,6 +93,26 @@ class PluginVersionChecker : ApplicationInitializedListener {
9793        }
9894    }
9995
96+     private  fun  shouldDisableToolkit (toolkit :  PluginInfo ? , updated :  List <PluginInfo >): Boolean  {
97+         if  (toolkit !=  null  &&  updated.none { it ==  toolkit }) {
98+             LOG .info { " Attempting to disable aws.toolkit due to known incompatibility" 
99+             val  descriptor =  toolkit.descriptor as ?  IdeaPluginDescriptor  ? :  run  {
100+                 LOG .warn { " Expected toolkit descriptor to be IdeaPluginDescriptor, but was ${toolkit.descriptor} " 
101+                 return  false 
102+             }
103+ 
104+             if  (! descriptor.isEnabled) {
105+                 LOG .info { " Does not need to disable toolkit since it is already disabled" 
106+                 return  false 
107+             }
108+ 
109+             PluginEnabler .HEADLESS .disable(listOf (descriptor))
110+             return  true 
111+         }
112+ 
113+         return  false 
114+     }
115+ 
100116    companion  object  {
101117        private  val  LOG  =  getLogger<PluginVersionChecker >()
102118    }
0 commit comments