Skip to content

Commit 3846f9b

Browse files
authored
Merge pull request #2656 from digma-ai/remove-listener-on-dispose
remove-listener-on-dispose
2 parents 7df261b + 0600cbf commit 3846f9b

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/reload/ReloadObserver.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class ReloadObserver(cs: CoroutineScope) {
7272
}
7373

7474

75+
//this method may throw exceptions
7576
fun register(project: Project, appName: String, jcefUiComponent: JComponent, parentDisposable: Disposable) {
7677

7778
Log.log(logger::trace, "register called for component {} in project {}", appName, project.name)

src/main/kotlin/org/digma/intellij/plugin/ui/jcef/JCefComponent.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ private constructor(
170170
AnalyticsServiceConnectionEvent.ANALYTICS_SERVICE_CONNECTION_EVENT_TOPIC, object : AnalyticsServiceConnectionEvent {
171171

172172

173-
174173
private fun shouldUpdateEngineStatus(): Boolean {
175174
//in installation wizard there is no need to update the status on connection lost if there is any engine operation
176175
// running (like install,stop,start,remove) because it may confuse the UI.
@@ -401,14 +400,29 @@ private constructor(
401400
fun registerForReloadObserver(registrationName: String) {
402401
//need to register for ReloadObserver after the component has been added to the parent so that all graphics configuration is set.
403402
//the event is called multiple times for the same component, but we need to register only once.
404-
getComponent().addAncestorListener(object : AncestorListenerAdapter() {
403+
val listener = object : AncestorListenerAdapter() {
405404
override fun ancestorAdded(event: AncestorEvent) {
406-
if (!registeredForReloadObserver) {
407-
registeredForReloadObserver = true
408-
service<ReloadObserver>().register(project, registrationName, getComponent(), parentDisposable)
405+
try {
406+
if (!registeredForReloadObserver) {
407+
registeredForReloadObserver = true
408+
service<ReloadObserver>().register(project, registrationName, getComponent(), parentDisposable)
409+
}
410+
} catch (e: Throwable) {
411+
Log.warnWithException(logger, project, e, "error in registerForReloadObserver.ancestorAdded")
412+
ErrorReporter.getInstance().reportError(project, "JCefComponent.registerForReloadObserver.ancestorAdded", e)
409413
}
410414
}
411-
})
415+
}
416+
417+
try {
418+
getComponent().addAncestorListener(listener)
419+
Disposer.register(parentDisposable) {
420+
getComponent().removeAncestorListener(listener)
421+
}
422+
} catch (e: Throwable) {
423+
Log.warnWithException(logger, project, e, "error in registerForReloadObserver.ancestorAdded")
424+
ErrorReporter.getInstance().reportError(project, "JCefComponent.registerForReloadObserver", e)
425+
}
412426
}
413427

414428

src/main/kotlin/org/digma/intellij/plugin/ui/notificationcenter/AppNotificationCenter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class AppNotificationCenter : Disposable {
7171
//also register as child of this service, so it is disposed with service
7272
Disposer.register(getInstance(), it)
7373
startAggressiveUpdateNotificationTimer(
74-
getInstance().aggressiveUpdateTimerDisposable!!,
74+
it,
7575
project,
7676
getInstance().currentlyShowingAggressiveUpdateNotifications
7777
)

0 commit comments

Comments
 (0)