@@ -13,6 +13,7 @@ import kotlinx.coroutines.isActive
1313import kotlinx.coroutines.launch
1414import org.apache.maven.artifact.versioning.ComparableVersion
1515import org.digma.intellij.plugin.analytics.AnalyticsService
16+ import org.digma.intellij.plugin.analytics.ApiClientChangedEvent
1617import org.digma.intellij.plugin.analytics.BackendConnectionEvent
1718import org.digma.intellij.plugin.common.EDT
1819import org.digma.intellij.plugin.common.ExceptionUtils
@@ -25,7 +26,6 @@ import org.digma.intellij.plugin.model.rest.version.BackendDeploymentType
2526import org.digma.intellij.plugin.model.rest.version.BackendVersionResponse
2627import org.digma.intellij.plugin.model.rest.version.VersionResponse
2728import org.digma.intellij.plugin.settings.InternalFileSettings
28- import org.digma.intellij.plugin.settings.SettingsState
2929import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
3030import java.util.concurrent.TimeUnit
3131import kotlin.time.Duration
@@ -93,27 +93,47 @@ class UpdatesService(private val project: Project) : Disposable {
9393
9494 override fun connectionGained () {
9595 Log .log(logger::debug, " got connectionGained" )
96- // update state immediately after connectionGained, so it will not wait the delay for checking the versions.
97- checkForNewerVersions()
96+
97+ try {
98+ // update state immediately after connectionGained, so it will not wait the delay for checking the versions.
99+ checkForNewerVersions()
100+ } catch (e: CancellationException ) {
101+ Log .debugWithException(logger, e, " Exception in checkForNewerVersions" )
102+ } catch (e: Throwable ) {
103+ Log .debugWithException(logger, e, " Exception in checkForNewerVersions {}" , ExceptionUtils .getNonEmptyMessage(e))
104+ ErrorReporter .getInstance().reportError(" UpdatesService.connectionGained" , e)
105+ }
98106 }
99107 })
100108
101109
102- SettingsState .getInstance().addChangeListener({
103- @Suppress(" UnstableApiUsage" )
104- disposingScope().launch {
105- // update state immediately after settings change. we are interested in api url change, but it will
106- // do no harm to call it on any settings change
107- checkForNewerVersions()
110+
111+ ApplicationManager .getApplication().messageBus.connect(this )
112+ .subscribe(ApiClientChangedEvent .API_CLIENT_CHANGED_TOPIC , object : ApiClientChangedEvent {
113+ override fun apiClientChanged (newUrl : String ) {
114+ @Suppress(" UnstableApiUsage" )
115+ disposingScope().launch {
116+ try {
117+ // update state immediately after settings change. we are interested in api url change, but it will
118+ // do no harm to call it on any settings change
119+ checkForNewerVersions()
120+ } catch (e: CancellationException ) {
121+ Log .debugWithException(logger, e, " Exception in checkForNewerVersions" )
122+ } catch (e: Throwable ) {
123+ Log .debugWithException(logger, e, " Exception in checkForNewerVersions {}" , ExceptionUtils .getNonEmptyMessage(e))
124+ ErrorReporter .getInstance().reportError(" UpdatesService.settingsChanged" , e)
125+ }
126+ }
108127 }
109128
110- }, this )
129+ } )
111130 }
112131
113132 override fun dispose () {
114133 // nothing to do , used as parent disposable
115134 }
116135
136+ // this method may throw exception, always catch and report
117137 private fun checkForNewerVersions () {
118138
119139 Log .log(logger::trace, " checking for new versions" )
0 commit comments