Skip to content

Commit 077f4ef

Browse files
change background task to lifetime task to avoid flickering of bottom toolbar on each auto refresh action
1 parent 653fb68 commit 077f4ef

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/kotlin/org/digma/intellij/plugin/ui/common/EnvironmentsPanel.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.digma.intellij.plugin.ui.common
22

33
import com.intellij.openapi.diagnostic.Logger
44
import com.intellij.openapi.project.Project
5+
import com.intellij.openapi.rd.util.launchBackground
56
import com.intellij.ui.components.ActionLink
67
import com.intellij.ui.components.JBLabel
78
import com.intellij.ui.components.JBPanel
@@ -10,9 +11,9 @@ import com.intellij.util.AlarmFactory
1011
import com.intellij.util.containers.stream
1112
import com.intellij.util.ui.JBUI
1213
import com.intellij.util.ui.WrapLayout
14+
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
1315
import org.digma.intellij.plugin.analytics.AnalyticsService
1416
import org.digma.intellij.plugin.analytics.EnvironmentChanged
15-
import org.digma.intellij.plugin.common.Backgroundable
1617
import org.digma.intellij.plugin.common.CommonUtils
1718
import org.digma.intellij.plugin.common.CommonUtils.prettyTimeOf
1819
import org.digma.intellij.plugin.log.Log
@@ -53,7 +54,7 @@ class EnvironmentsPanel(
5354
localHostname = CommonUtils.getLocalHostname()
5455
isOpaque = false
5556
layout = WrapLayout(FlowLayout.LEFT, 2, 0)
56-
rebuildInBackground(project)
57+
rebuildInBackground()
5758

5859
project.messageBus.connect(project.getService(AnalyticsService::class.java))
5960
.subscribe(EnvironmentChanged.ENVIRONMENT_CHANGED_TOPIC, object : EnvironmentChanged {
@@ -71,10 +72,10 @@ class EnvironmentsPanel(
7172

7273
override fun environmentsListChanged(newEnvironments: MutableList<String>?) {
7374
if (SwingUtilities.isEventDispatchThread()) {
74-
rebuildInBackground(project)
75+
rebuildInBackground()
7576
} else {
7677
SwingUtilities.invokeLater {
77-
rebuildInBackground(project)
78+
rebuildInBackground()
7879
}
7980
}
8081
}
@@ -83,7 +84,7 @@ class EnvironmentsPanel(
8384

8485

8586
override fun reset() {
86-
rebuildInBackground(project)
87+
rebuildInBackground()
8788
}
8889

8990
/*
@@ -153,18 +154,19 @@ class EnvironmentsPanel(
153154

154155
}
155156

156-
private fun rebuildInBackground(project: Project) {
157-
val task = Runnable {
157+
private fun rebuildInBackground() {
158+
val lifetimeDefinition = LifetimeDefinition()
159+
lifetimeDefinition.lifetime.launchBackground {
158160
rebuildPanelLock.lock()
159161
Log.log(logger::debug, "Lock acquired for rebuild Envs panel process.")
160162
try {
161163
rebuild()
162164
} finally {
163165
rebuildPanelLock.unlock()
164166
Log.log(logger::debug, "Lock released for rebuild Envs panel process.")
167+
lifetimeDefinition.terminate()
165168
}
166169
}
167-
Backgroundable.ensureBackground(project, "Rebuilding environments panel", task)
168170
}
169171

170172
private fun rebuild() {

0 commit comments

Comments
 (0)