Revert "[platform] refactoring Defender notifications (IJ-CR-148744)"

This reverts commit 23024af4354c8870d5547c2d40cd9b8e3698a348.

GitOrigin-RevId: 98364669edcb0d32eab66be68eac71866ba250b5
This commit is contained in:
Vera Petrenkova
2024-11-26 11:28:32 +00:00
committed by intellij-monorepo-bot
parent c1f294790e
commit 7b043eb215
2 changed files with 11 additions and 16 deletions
@@ -34,6 +34,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -89,18 +90,19 @@ public class WindowsDefenderChecker {
@ApiStatus.Internal
@RequiresBackgroundThread
final @Nullable Boolean isAlreadyProcessed(@NotNull Project project) {
final boolean isAlreadyProcessed(@NotNull Project project, Consumer<@Nullable Boolean> notifyAction) {
var projectPath = getProjectPath(project);
if (projectPath != null && myProjectPaths.containsKey(projectPath)) {
while (!project.isDisposed() && myProjectPaths.get(projectPath) == null) TimeoutUtil.sleep(100);
var success = myProjectPaths.remove(projectPath);
Boolean success = myProjectPaths.remove(projectPath);
if (success == Boolean.TRUE) {
PropertiesComponent.getInstance(project).setValue(IGNORE_STATUS_CHECK, true);
}
return success;
notifyAction.accept(success);
return true;
}
return null;
return false;
}
private static @Nullable Path getProjectPath(Project project) {
@@ -44,19 +44,19 @@ internal class WindowsDefenderCheckerActivity : ProjectActivity {
WindowsDefenderStatisticsCollector.configured(project, success)
// otherwise, the notification will be shown on project opening
//otherwise notification will be sent after project opening
if (project != null) {
notify(project, success)
}
}
}
private fun notify(project: Project, success: Boolean) {
private fun notify(project: Project, success: Boolean?) {
if (success == true) {
Notification("WindowsDefender", DiagnosticBundle.message("defender.config.success"), NotificationType.INFORMATION)
.notify(project)
}
else {
else if ( success == false){
Notification("WindowsDefender", DiagnosticBundle.message("defender.config.failed"), NotificationType.ERROR)
.addAction(ShowLogAction.notificationAction())
.notify(project)
@@ -73,20 +73,13 @@ internal class WindowsDefenderCheckerActivity : ProjectActivity {
override suspend fun execute(project: Project) {
val checker = serviceAsync<WindowsDefenderChecker>()
if (checker.isStatusCheckIgnored(project)) {
val alreadyProcessed = checker.isAlreadyProcessed(project) { success: Boolean? -> notify(project, success) }
if (checker.isStatusCheckIgnored(project) || alreadyProcessed) {
LOG.info("status check is disabled")
WindowsDefenderStatisticsCollector.protectionCheckSkipped(project)
return
}
val alreadyProcessed = checker.isAlreadyProcessed(project)
if (alreadyProcessed != null) {
notify(project, success = alreadyProcessed)
LOG.info("requested from the \"trust project\" dialog; success=${alreadyProcessed}")
return
}
@OptIn(IntellijInternalApi::class, DelicateCoroutinesApi::class)
computeDetached {
checkDefenderStatus(project, checker)