Skip to content

Commit

Permalink
Some thread-safety modifications in MacOSThemeDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
Dansoftowner committed Apr 16, 2021
1 parent bb40a52 commit dec4722
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/java/com/jthemedetecor/MacOSThemeDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ class MacOSThemeDetector extends OsThemeDetector {

private final Set<Consumer<Boolean>> listeners = Collections.synchronizedSet(new HashSet<>());
private final Pattern themeNamePattern = Pattern.compile(".*dark.*", Pattern.CASE_INSENSITIVE);
private final Object iterateLock = new Object();

private final Callback themeChangedCallback = new Callback() {
@SuppressWarnings("unused")
public void callback() {
synchronized (iterateLock) {
synchronized (listeners) {
notifyListeners(isDark());
}
}
Expand Down Expand Up @@ -100,14 +99,14 @@ private boolean isDarkTheme(String themeName) {

@Override
public void registerListener(@NotNull Consumer<Boolean> darkThemeListener) {
synchronized (iterateLock) {
synchronized (listeners) {
listeners.add(darkThemeListener);
}
}

@Override
public void removeListener(@Nullable Consumer<Boolean> darkThemeListener) {
synchronized (iterateLock) {
synchronized (listeners) {
listeners.remove(darkThemeListener);
}
}
Expand Down

0 comments on commit dec4722

Please sign in to comment.