only remove system theme change listener, if one was previously registered.

This commit is contained in:
Armin Schrenk
2021-02-24 12:54:56 +01:00
parent fed572694f
commit a17b416262

View File

@@ -137,13 +137,13 @@ public class FxApplication extends Application {
}
private void appThemeChanged(@SuppressWarnings("unused") ObservableValue<? extends UiTheme> observable, @SuppressWarnings("unused") UiTheme oldValue, UiTheme newValue) {
appearanceProvider.ifPresent(appearanceProvider -> {
if (appearanceProvider.isPresent() && oldValue == UiTheme.AUTOMATIC && newValue != UiTheme.AUTOMATIC) {
try {
appearanceProvider.removeListener(systemInterfaceThemeListener);
appearanceProvider.get().removeListener(systemInterfaceThemeListener);
} catch (UiAppearanceException e) {
LOG.error("Failed to disable automatic theme switching.");
}
});
}
loadSelectedStyleSheet(newValue);
}