Show "Configure Kotlin" notification at most once after project opening
Don't show notification after every sync; trigger it from rootsChanged handler because the root model is not yet updated at syncDone point #KT-16590 Fixed
This commit is contained in:
+34
-19
@@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.configuration.ui
|
package org.jetbrains.kotlin.idea.configuration.ui
|
||||||
|
|
||||||
|
import com.intellij.ProjectTopics
|
||||||
import com.intellij.notification.NotificationDisplayType
|
import com.intellij.notification.NotificationDisplayType
|
||||||
import com.intellij.notification.NotificationsConfiguration
|
import com.intellij.notification.NotificationsConfiguration
|
||||||
import com.intellij.openapi.components.AbstractProjectComponent
|
import com.intellij.openapi.components.AbstractProjectComponent
|
||||||
import com.intellij.openapi.project.DumbService
|
import com.intellij.openapi.project.DumbService
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.roots.ModuleRootAdapter
|
||||||
|
import com.intellij.openapi.roots.ModuleRootEvent
|
||||||
import com.intellij.openapi.startup.StartupManager
|
import com.intellij.openapi.startup.StartupManager
|
||||||
import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
|
import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
|
||||||
import org.jetbrains.kotlin.idea.configuration.showConfigureKotlinNotificationIfNeeded
|
import org.jetbrains.kotlin.idea.configuration.showConfigureKotlinNotificationIfNeeded
|
||||||
@@ -30,11 +33,27 @@ import org.jetbrains.kotlin.idea.versions.findOutdatedKotlinLibraries
|
|||||||
import org.jetbrains.kotlin.idea.versions.notifyOutdatedKotlinRuntime
|
import org.jetbrains.kotlin.idea.versions.notifyOutdatedKotlinRuntime
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
class KotlinConfigurationCheckerComponent protected constructor(project: Project) : AbstractProjectComponent(project) {
|
class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectComponent(project) {
|
||||||
private var syncCount = AtomicInteger()
|
private val syncDepth = AtomicInteger()
|
||||||
|
@Volatile private var notificationPostponed = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
NotificationsConfiguration.getNotificationsConfiguration().register(CONFIGURE_NOTIFICATION_GROUP_ID, NotificationDisplayType.STICKY_BALLOON, true)
|
NotificationsConfiguration.getNotificationsConfiguration().register(CONFIGURE_NOTIFICATION_GROUP_ID, NotificationDisplayType.STICKY_BALLOON, true)
|
||||||
|
|
||||||
|
val connection = project.messageBus.connect()
|
||||||
|
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootAdapter() {
|
||||||
|
override fun rootsChanged(event: ModuleRootEvent?) {
|
||||||
|
if (notificationPostponed && !isSyncing) {
|
||||||
|
DumbService.getInstance(myProject).smartInvokeLater {
|
||||||
|
if (!isSyncing) {
|
||||||
|
notificationPostponed = false
|
||||||
|
showConfigureKotlinNotificationIfNeeded(myProject,
|
||||||
|
collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(myProject)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun projectOpened() {
|
override fun projectOpened() {
|
||||||
@@ -50,31 +69,27 @@ class KotlinConfigurationCheckerComponent protected constructor(project: Project
|
|||||||
if (!libraries.isEmpty()) {
|
if (!libraries.isEmpty()) {
|
||||||
notifyOutdatedKotlinRuntime(myProject, libraries)
|
notifyOutdatedKotlinRuntime(myProject, libraries)
|
||||||
}
|
}
|
||||||
if (syncCount.get() == 0) {
|
if (syncDepth.get() == 0) {
|
||||||
showConfigureKotlinNotificationIfNeeded(myProject,
|
showConfigureKotlinNotificationIfNeeded(myProject,
|
||||||
collectModulesWithOutdatedRuntime(libraries))
|
collectModulesWithOutdatedRuntime(libraries))
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
}
|
notificationPostponed = true
|
||||||
}
|
|
||||||
|
|
||||||
val isSyncing: Boolean get() = syncCount.get() > 0
|
|
||||||
|
|
||||||
fun syncStarted() {
|
|
||||||
syncCount.incrementAndGet()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun syncDone() {
|
|
||||||
if (syncCount.decrementAndGet() == 0) {
|
|
||||||
DumbService.getInstance(myProject).smartInvokeLater {
|
|
||||||
if (!isSyncing) {
|
|
||||||
showConfigureKotlinNotificationIfNeeded(myProject,
|
|
||||||
collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(myProject)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isSyncing: Boolean get() = syncDepth.get() > 0
|
||||||
|
|
||||||
|
fun syncStarted() {
|
||||||
|
syncDepth.incrementAndGet()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun syncDone() {
|
||||||
|
syncDepth.decrementAndGet()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project"
|
val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user