Skip to content

Commit

Permalink
Fail Laf installation if laf is currently being installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed Aug 1, 2021
1 parent a9ae43f commit 8f8194e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/com/github/weisj/darklaf/LafInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,10 +39,14 @@
final class LafInstaller {

private static final Logger LOGGER = LogUtil.getLogger(LafManager.class);
private static final AtomicBoolean isInstalling = new AtomicBoolean(false);
private static final ThemeEventSupport<ThemeChangeEvent, ThemeChangeListener> 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();
Expand All @@ -51,6 +56,8 @@ void install(final Theme theme) {
notifyThemeInstalled(theme);
} catch (final UnsupportedLookAndFeelException e) {
LOGGER.log(Level.SEVERE, "Could not install LaF", e);
} finally {
isInstalling.set(false);
}
}

Expand Down

0 comments on commit 8f8194e

Please sign in to comment.