Skip to content

Commit

Permalink
Fix 'Slow operations are prohibited on EDT' error after project opening
Browse files Browse the repository at this point in the history
  • Loading branch information
Krotki committed Dec 13, 2024
1 parent 4ec1599 commit d5ac084
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Fix 'Slow operations are prohibited on EDT' error after project opening

## [2024.3.1] - 2024-11-14

- Support for intellij platform 2024.3
Expand Down
81 changes: 41 additions & 40 deletions src/main/kotlin/io/vlang/ide/VlangPostStartupActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.ide.BrowserUtil
import com.intellij.ide.plugins.InstalledPluginsState
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.application.readAction
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -50,11 +51,50 @@ class VlangPostStartupActivity : ProjectActivity {

checkUpdates(project)

invokeLater {
readAction {
project.projectStructure.determineProjectStructure(project)
}
}

private fun checkUpdates(project: Project) {
val hasNewerVersion = InstalledPluginsState.getInstance().hasNewerVersion(PLUGIN_ID)
if (!hasNewerVersion) {
return
}

val plugin = PluginManagerCore.getPlugin(PLUGIN_ID) ?: return
val currentVersion = plugin.version

val dontShowForVersion = PropertiesComponent.getInstance(project).getValue(DONT_SHOW_UPDATE_NOTIFICATION)
if (dontShowForVersion != null && dontShowForVersion == currentVersion) {
// skip any update for current version
return
}

VlangNotification("New version of the V plugin is available")
.withActions(
VlangNotification.Action("Update") { _, notification ->
invokeLater {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "Plugins")
notification.expire()
}
}
)
.withActions(
VlangNotification.Action("What's new?") { _, notification ->
BrowserUtil.browse("${PLUGIN_URL}/versions")
notification.expire()
}
)
.withActions(
VlangNotification.Action("Don't show again") { _, notification ->
PropertiesComponent.getInstance(project).setValue(DONT_SHOW_UPDATE_NOTIFICATION, currentVersion, null)
notification.expire()
}
)
.show(project)
}

companion object {
fun setupToolchainCandidates(): List<String> {
val toolchainCandidates = VlangToolchainFlavor.getApplicableFlavors()
Expand All @@ -70,45 +110,6 @@ class VlangPostStartupActivity : ProjectActivity {
return toolchainCandidates
}

private fun checkUpdates(project: Project) {
val hasNewerVersion = InstalledPluginsState.getInstance().hasNewerVersion(PLUGIN_ID)
if (!hasNewerVersion) {
return
}

val plugin = PluginManagerCore.getPlugin(PLUGIN_ID) ?: return
val currentVersion = plugin.version

val dontShowForVersion = PropertiesComponent.getInstance(project).getValue(DONT_SHOW_UPDATE_NOTIFICATION)
if (dontShowForVersion != null && dontShowForVersion == currentVersion) {
// skip any update for current version
return
}

VlangNotification("New version of the V plugin is available")
.withActions(
VlangNotification.Action("Update") { _, notification ->
invokeLater {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "Plugins")
notification.expire()
}
}
)
.withActions(
VlangNotification.Action("What's new?") { _, notification ->
BrowserUtil.browse("${PLUGIN_URL}/versions")
notification.expire()
}
)
.withActions(
VlangNotification.Action("Don't show again") { _, notification ->
PropertiesComponent.getInstance(project).setValue(DONT_SHOW_UPDATE_NOTIFICATION, currentVersion, null)
notification.expire()
}
)
.show(project)
}

private val PLUGIN_ID = PluginId.getId("io.vlang")
private val PLUGIN_URL = "https://plugins.jetbrains.com/plugin/24183-vlang"
private const val DONT_SHOW_UPDATE_NOTIFICATION = "io.vlang.dont.show.update.notification"
Expand Down

0 comments on commit d5ac084

Please sign in to comment.