mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 15:52:01 +07:00
IJPL-164095 Don't show 'Windows Defender' notification if 'Trust and Open Project' dialog was just shown
(cherry picked from commit 12c3c1db07c402cec0786375e1ee2861aeff0e39) IJ-CR-147809 GitOrigin-RevId: 8b30986057998b245864bbdac1eea3817fad0b61
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f7a7e7f698
commit
5cb1d12a39
@@ -18,6 +18,7 @@ import com.intellij.openapi.util.IntellijInternalApi
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.util.io.computeDetached
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlin.io.path.Path
|
||||
|
||||
private val LOG = logger<WindowsDefenderCheckerActivity>()
|
||||
|
||||
@@ -31,9 +32,11 @@ internal class WindowsDefenderCheckerActivity : ProjectActivity {
|
||||
|
||||
override suspend fun execute(project: Project) {
|
||||
val checker = serviceAsync<WindowsDefenderChecker>()
|
||||
val pathsToExclude = WindowsDefenderExcludeUtil.getPathsToExclude()
|
||||
if (pathsToExclude.isNotEmpty()) {
|
||||
WindowsDefenderExcludeUtil.updateDefenderConfig(checker, project, pathsToExclude) { pathsToExclude.clear() }
|
||||
WindowsDefenderExcludeUtil.updateDefenderConfig(checker, project, pathsToExclude) { WindowsDefenderExcludeUtil.clearPathsToExclude() }
|
||||
}
|
||||
if (project.basePath != null && WindowsDefenderExcludeUtil.isDefenderShown(Path(project.basePath!!))) return
|
||||
if (checker.isStatusCheckIgnored(project)) {
|
||||
LOG.info("status check is disabled")
|
||||
WindowsDefenderStatisticsCollector.protectionCheckSkipped(project)
|
||||
|
||||
@@ -9,11 +9,33 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.NlsContexts
|
||||
import com.intellij.platform.ide.CoreUiCoroutineScopeHolder
|
||||
import com.intellij.platform.ide.progress.withBackgroundProgress
|
||||
import com.jetbrains.rd.util.collections.SynchronizedList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.launch
|
||||
import java.nio.file.Path
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
internal object WindowsDefenderExcludeUtil {
|
||||
private val defenderExclusions = ConcurrentHashMap<Path, Boolean>()
|
||||
|
||||
fun markPathAsShownDefender(path: Path) {
|
||||
defenderExclusions.putIfAbsent(path, false)
|
||||
}
|
||||
|
||||
fun isDefenderShown(path: Path): Boolean {
|
||||
return defenderExclusions.containsKey(path)
|
||||
}
|
||||
|
||||
fun addPathsToExclude(paths: List<Path>) {
|
||||
paths.forEach { defenderExclusions.put(it, true) }
|
||||
}
|
||||
|
||||
fun getPathsToExclude(): List<Path> {
|
||||
return defenderExclusions.filterValues{it}.keys.toImmutableList()
|
||||
}
|
||||
|
||||
fun clearPathsToExclude() {
|
||||
defenderExclusions.replaceAll { _, _ -> false }
|
||||
}
|
||||
|
||||
fun updateDefenderConfig(checker: WindowsDefenderChecker, project: Project, paths: List<Path>, onSuccess: () -> Unit = {}) {
|
||||
service<CoreUiCoroutineScopeHolder>().coroutineScope.launch {
|
||||
@@ -38,6 +60,4 @@ internal object WindowsDefenderExcludeUtil {
|
||||
|
||||
internal fun notification(@NlsContexts.NotificationContent content: String, type: NotificationType): Notification =
|
||||
Notification("WindowsDefender", DiagnosticBundle.message("notification.group.defender.config"), content, type)
|
||||
}
|
||||
|
||||
internal val pathsToExclude = SynchronizedList<Path>()
|
||||
}
|
||||
@@ -5,7 +5,6 @@ package com.intellij.ide.trustedProjects
|
||||
|
||||
import com.intellij.diagnostic.WindowsDefenderChecker
|
||||
import com.intellij.diagnostic.WindowsDefenderExcludeUtil
|
||||
import com.intellij.diagnostic.pathsToExclude
|
||||
import com.intellij.ide.IdeBundle
|
||||
import com.intellij.ide.impl.OpenUntrustedProjectChoice
|
||||
import com.intellij.ide.impl.TRUSTED_PROJECTS_HELP_TOPIC
|
||||
@@ -74,12 +73,16 @@ object TrustedProjectsDialog {
|
||||
|
||||
TrustedProjectsStatistics.NEW_PROJECT_OPEN_OR_IMPORT_CHOICE.log(openChoice)
|
||||
|
||||
if (isWinDefenderEnabled && windowDefenderPathsToExclude.isNotEmpty()) {
|
||||
if (project != null) {
|
||||
val checker = serviceAsync<WindowsDefenderChecker>()
|
||||
WindowsDefenderExcludeUtil.updateDefenderConfig(checker, project, windowDefenderPathsToExclude)
|
||||
} else {
|
||||
pathsToExclude.addAll(windowDefenderPathsToExclude)
|
||||
if (isWinDefenderEnabled) {
|
||||
WindowsDefenderExcludeUtil.markPathAsShownDefender(projectRoot)
|
||||
if (windowDefenderPathsToExclude.isNotEmpty()) {
|
||||
if (project != null) {
|
||||
val checker = serviceAsync<WindowsDefenderChecker>()
|
||||
WindowsDefenderExcludeUtil.updateDefenderConfig(checker, project, windowDefenderPathsToExclude)
|
||||
}
|
||||
else {
|
||||
WindowsDefenderExcludeUtil.addPathsToExclude(windowDefenderPathsToExclude)
|
||||
}
|
||||
}
|
||||
}
|
||||
return openChoice != OpenUntrustedProjectChoice.CANCEL
|
||||
|
||||
Reference in New Issue
Block a user