From 7cb586303973d4854a96790ef35ed5859da83afc Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Wed, 2 Nov 2022 23:32:20 +0200 Subject: [PATCH] Fix trying start the timer more then one if you closed the project and open a new one issue --- .../anas/intellij/plugins/ayah/AyahStartupActivity.java | 5 +++-- .../com/anas/intellij/plugins/ayah/NotificationTimer.java | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java b/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java index 525e35f..6566ebf 100644 --- a/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java +++ b/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java @@ -7,6 +7,7 @@ import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupActivity; +import lombok.val; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -18,11 +19,11 @@ import java.io.IOException; public class AyahStartupActivity implements StartupActivity { @Override public void runActivity(@NotNull final Project project) { - final var basmalhOnStartSettingsState = AyahSettingsState.getInstance().getBasmalhOnStart(); + val basmalhOnStartSettingsState = AyahSettingsState.getInstance().getBasmalhOnStart(); // Basmalh on start if (basmalhOnStartSettingsState.isActive()) { try { - final var bassmalh = Ayah.getAyah(1, + val bassmalh = Ayah.getAyah(1, basmalhOnStartSettingsState.getEdition().getEditionIdentifier()); NotificationGroupManager.getInstance() .getNotificationGroup("Basmalh on Start") diff --git a/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimer.java b/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimer.java index 91ccfd6..0a22b24 100644 --- a/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimer.java +++ b/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimer.java @@ -16,14 +16,21 @@ public enum NotificationTimer { private final Timer timer; private final NotificationTimerTask notificationTimerTask; + private boolean isRunning; NotificationTimer() { timer = new Timer(); notificationTimerTask = new NotificationTimerTask(); + isRunning = false; } public void start(@NotNull Project project) { + if (isRunning) { + return; + } notificationTimerTask.setProject(project); schedule(AyahSettingsState.getInstance().getIntervalTimeBetweenNotifications()); + isRunning = true; + } public void updateIntervalTimeBetweenNotifications(final int intervalTimeBetweenNotifications) {