From f44fbde5151c42f874401dae1a6e814177eeec25 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Sun, 1 Aug 2021 12:10:11 +0200 Subject: [PATCH] Fail Laf installation if laf is currently being installed. --- .../main/java/com/github/weisj/darklaf/LafInstaller.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/main/java/com/github/weisj/darklaf/LafInstaller.java b/core/src/main/java/com/github/weisj/darklaf/LafInstaller.java index 20793496..3c372f06 100644 --- a/core/src/main/java/com/github/weisj/darklaf/LafInstaller.java +++ b/core/src/main/java/com/github/weisj/darklaf/LafInstaller.java @@ -22,6 +22,7 @@ package com.github.weisj.darklaf; import java.awt.Window; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,10 +39,14 @@ import com.github.weisj.darklaf.util.LogUtil; final class LafInstaller { private static final Logger LOGGER = LogUtil.getLogger(LafManager.class); + private static final AtomicBoolean isInstalling = new AtomicBoolean(false); private static final ThemeEventSupport eventSupport = new ThemeEventSupport<>(); void install(final Theme theme) { + if (!isInstalling.compareAndSet(false, true)) { + throw new IllegalStateException("Can't install Laf while installation is in progress"); + } try { LOGGER.fine(() -> "Installing theme " + theme); LafTransition transition = LafTransition.showSnapshot(); @@ -51,6 +56,8 @@ final class LafInstaller { notifyThemeInstalled(theme); } catch (final UnsupportedLookAndFeelException e) { LOGGER.log(Level.SEVERE, "Could not install LaF", e); + } finally { + isInstalling.set(false); } }