@@ -21,6 +21,7 @@ import software.aws.toolkits.core.utils.warn
21
21
import software.aws.toolkits.jetbrains.AwsToolkit.TOOLKIT_PLUGIN_ID
22
22
import software.aws.toolkits.jetbrains.core.plugin.PluginUpdateManager
23
23
import software.aws.toolkits.resources.message
24
+ import javax.swing.SwingUtilities
24
25
25
26
class PluginVersionChecker : ApplicationInitializedListener {
26
27
override suspend fun execute (asyncScope : CoroutineScope ) {
@@ -51,19 +52,14 @@ class PluginVersionChecker : ApplicationInitializedListener {
51
52
52
53
// defensively disable the old toolkit if we couldn't update it because we might deadlock during project open
53
54
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
- }
63
55
64
- if (shouldDisableToolkit || updated.isNotEmpty()) {
56
+ if (shouldDisableToolkit(toolkit, updated) || updated.isNotEmpty()) {
65
57
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
+ }
67
63
return
68
64
}
69
65
@@ -82,7 +78,7 @@ class PluginVersionChecker : ApplicationInitializedListener {
82
78
coreDescriptor?.let { descriptor -> PluginUpdateManager .updatePlugin(descriptor, EmptyProgressIndicator ()) }
83
79
}
84
80
85
- PluginEnabler .getInstance() .disable(
81
+ PluginEnabler .HEADLESS .disable(
86
82
AwsToolkit .PLUGINS_INFO .values.mapNotNull {
87
83
val descriptor = it.descriptor as ? IdeaPluginDescriptor
88
84
if (descriptor != null && descriptor != core.descriptor) {
@@ -97,6 +93,26 @@ class PluginVersionChecker : ApplicationInitializedListener {
97
93
}
98
94
}
99
95
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
+
100
116
companion object {
101
117
private val LOG = getLogger<PluginVersionChecker >()
102
118
}
0 commit comments