From cb399b623d113bcd801b7966b1f37255e5dcc6db Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Mon, 3 Jun 2013 15:09:09 +0200 Subject: [PATCH] show notification once before its expiration --- .../src/com/intellij/idea/IdeaApplication.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 965def15d89b..1641c8dd7838 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -57,6 +57,7 @@ import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; @SuppressWarnings({"CallToPrintStackTrace"}) public class IdeaApplication { @@ -123,12 +124,17 @@ public class IdeaApplication { IconLoader.activate(); new JFrame().pack(); // this peer will prevent shutting down our application + final File file = new File(PathManager.getSystemPath()); + final AtomicBoolean reported = new AtomicBoolean(); + final long lowDiskSpaceThreshold = 50 * 1024 * 1024; + JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() { @Override public void run() { - final long lowDiskSpaceThreshold = 50 * 1024 * 1024; - if (file.getUsableSpace() < lowDiskSpaceThreshold) { + if (!reported.get() && file.getUsableSpace() < lowDiskSpaceThreshold) { + reported.compareAndSet(false, true); + //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -138,8 +144,12 @@ public class IdeaApplication { ? "Low disk space on disk where system directory of " + fullProductName + " is located" : "System directory of " + fullProductName + " is read only"; new NotificationGroup("System", NotificationDisplayType.STICKY_BALLOON, false) - .createNotification(title, file.getPath(), NotificationType.INFORMATION, null).notify( - null); + .createNotification(title, file.getPath(), NotificationType.INFORMATION, null).whenExpired(new Runnable() { + @Override + public void run() { + reported.compareAndSet(true, false); + } + }).notify(null); } }); }