From e7a9defa08e8dce016372a7dcb6afb6c7a63c460 Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Tue, 13 Oct 2020 17:18:35 +0300 Subject: [PATCH] [dynamic plugins] applicationShuttingDown is still required #IDEA-246104 GitOrigin-RevId: 65a917558d890bf358d0e0ba4715cdedd8fd6a63 --- .../ide/plugins/ProjectPluginTracker.kt | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/ProjectPluginTracker.kt b/platform/platform-impl/src/com/intellij/ide/plugins/ProjectPluginTracker.kt index db6227f60eda..67345981f6e7 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/ProjectPluginTracker.kt +++ b/platform/platform-impl/src/com/intellij/ide/plugins/ProjectPluginTracker.kt @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.plugins +import com.intellij.ide.AppLifecycleListener import com.intellij.openapi.application.ApplicationManager.getApplication import com.intellij.openapi.components.* import com.intellij.openapi.extensions.ExtensionNotApplicableException @@ -70,20 +71,33 @@ internal class ProjectPluginTracker(project: Project) : PersistentStateComponent } private fun updatePluginEnabledState(project: Project, enable: Boolean) { - getInstance(project).state - .updatePluginEnabledState(project, enable) + val pluginTracker = getInstance(project) + if (pluginTracker.applicationShuttingDown) return + + pluginTracker.state.updatePluginEnabledState(project, enable) } } private var state = State() + private var applicationShuttingDown = false init { - getApplication().messageBus.connect(project).subscribe( + val connection = getApplication().messageBus.connect(project) + connection.subscribe( ProjectManager.TOPIC, object : ProjectManagerListener { override fun projectClosing(project: Project) = updatePluginEnabledState(project, false) } ) + + connection.subscribe( + AppLifecycleListener.TOPIC, + object : AppLifecycleListener { + override fun appWillBeClosed(isRestart: Boolean) { + applicationShuttingDown = true + } + } + ) } override fun getState(): State = state