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. 17
      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 class DarkLaf extends BasicLookAndFeel {
public static final String SYSTEM_PROPERTY_PREFIX = "darklaf."; 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()); private static final Logger LOGGER = Logger.getLogger(DarkLaf.class.getName());
/* /*
* All tasks for initializing the ui defaults in order of execution. * 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() { protected DecorationsHandler() {
try { try {
//Extend for different platforms. //Extend for different platforms.
boolean enableDecorations = boolean enableDecorations = isNativeDecorationsEnabled();
!PropertyValue.FALSE.equals(System.getProperty(DECORATIONS_FLAG));
if (SystemInfo.isWindows10 && enableDecorations) { if (SystemInfo.isWindows10 && enableDecorations) {
//Decorations are in the Windows10 visuals. Disable for older version. //Decorations are in the Windows10 visuals. Disable for older version.
decorationsProvider = new WindowsDecorationsProvider(); decorationsProvider = new WindowsDecorationsProvider();
@ -91,6 +90,11 @@ public class DecorationsHandler {
&& LafManager.getTheme().useCustomDecorations(); && 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() { public void initialize() {
decorationsProvider.initialize(); decorationsProvider.initialize();
} }

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

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

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