Browse Source

Made LafManager#enablePreferenceChangeReporting only toggle reporting.

Disabling the use of native os settings in LafManager#getPrefferedThemeStyle must be done through the system properties `darklaf.enableNativePreferences` or `darklaf.allowNativeCode`.
pull/130/head
weisj 5 years ago
parent
commit
f2958a2b76
  1. 1
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  2. 8
      core/src/main/java/com/github/weisj/darklaf/platform/DecorationsHandler.java
  3. 15
      core/src/main/java/com/github/weisj/darklaf/platform/ThemePreferencesHandler.java
  4. 6
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java

1
core/src/main/java/com/github/weisj/darklaf/DarkLaf.java

@ -42,6 +42,7 @@ import java.util.logging.Logger;
public class DarkLaf extends BasicLookAndFeel {
public static final String SYSTEM_PROPERTY_PREFIX = "darklaf.";
public static final String ALLOW_NATIVE_CODE_FLAG = DarkLaf.SYSTEM_PROPERTY_PREFIX + "allowNativeCode";
private static final Logger LOGGER = Logger.getLogger(DarkLaf.class.getName());
/*
* All tasks for initializing the ui defaults in order of execution.

8
core/src/main/java/com/github/weisj/darklaf/platform/DecorationsHandler.java

@ -55,8 +55,7 @@ public class DecorationsHandler {
protected DecorationsHandler() {
try {
//Extend for different platforms.
boolean enableDecorations =
!PropertyValue.FALSE.equals(System.getProperty(DECORATIONS_FLAG));
boolean enableDecorations = isNativeDecorationsEnabled();
if (SystemInfo.isWindows10 && enableDecorations) {
//Decorations are in the Windows10 visuals. Disable for older version.
decorationsProvider = new WindowsDecorationsProvider();
@ -91,6 +90,11 @@ public class DecorationsHandler {
&& LafManager.getTheme().useCustomDecorations();
}
private boolean isNativeDecorationsEnabled() {
return !PropertyValue.FALSE.equals(System.getProperty(DECORATIONS_FLAG))
&& !PropertyValue.FALSE.equals(System.getProperty(DarkLaf.ALLOW_NATIVE_CODE_FLAG));
}
public void initialize() {
decorationsProvider.initialize();
}

15
core/src/main/java/com/github/weisj/darklaf/platform/ThemePreferencesHandler.java

@ -35,7 +35,7 @@ import com.github.weisj.darklaf.util.SystemInfo;
public class ThemePreferencesHandler {
public static final String PREFERENCE_REPORTING_FLAG = DarkLaf.SYSTEM_PROPERTY_PREFIX + "themePreferenceReporting";
public static final String PREFERENCE_REPORTING_FLAG = DarkLaf.SYSTEM_PROPERTY_PREFIX + "enableNativePreferences";
private static ThemePreferencesHandler sharedInstance;
private final ThemePreferenceChangeSupport changeSupport = new ThemePreferenceChangeSupport();
@ -54,9 +54,8 @@ public class ThemePreferencesHandler {
protected ThemePreferencesHandler() {
try {
// Extend for different platforms.
boolean enableDecorations =
!PropertyValue.FALSE.equals(System.getProperty(PREFERENCE_REPORTING_FLAG));
if (SystemInfo.isWindows10 && enableDecorations) {
boolean enableNativePreferences = isNativePreferencesEnabled();
if (SystemInfo.isWindows10 && enableNativePreferences) {
// Decorations are in the Windows10 visuals. Disable for older version.
preferenceProvider = new WindowsThemePreferenceProvider();
} else {
@ -66,6 +65,7 @@ public class ThemePreferencesHandler {
// If decorations modules are not available disable them.
preferenceProvider = new DefaultThemePreferenceProvider();
}
preferenceProvider.initialize();
preferenceProvider.setCallback(this::onChange);
}
@ -82,11 +82,12 @@ public class ThemePreferencesHandler {
}
public void enablePreferenceChangeReporting(final boolean enabled) {
boolean oldEnabled = isPreferenceChangeReportingEnabled();
preferenceProvider.setReporting(enabled);
if (isPreferenceChangeReportingEnabled() != oldEnabled && enabled) {
preferenceProvider.initialize();
}
private boolean isNativePreferencesEnabled() {
return !PropertyValue.FALSE.equals(System.getProperty(PREFERENCE_REPORTING_FLAG))
&& !PropertyValue.FALSE.equals(System.getProperty(DarkLaf.ALLOW_NATIVE_CODE_FLAG));
}
public boolean isPreferenceChangeReportingEnabled() {

6
windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java

@ -60,15 +60,15 @@ public class WindowsLibrary {
} else {
LOGGER.warning("Could not determine jre model '"
+ SystemInfo.jreArchitecture
+ "'. Decorations will be disabled");
+ "'. Native features will be disabled");
return;
}
loaded = true;
LOGGER.info("Loaded darklaf-windows.dll. Decorations are enabled.");
LOGGER.info("Loaded darklaf-windows.dll. Native features are enabled.");
} catch (Throwable e) {
//Library not found, SecurityManager prevents library loading etc.
LOGGER.log(Level.SEVERE, "Could not load decorations library darklaf-windows.dll." +
" Decorations will be disabled", e);
" Native features will be disabled", e);
}
}

Loading…
Cancel
Save