From 44e683ae619fe4befb59529399b6f03cf27cf718 Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Sat, 16 May 2020 01:26:32 -0700 Subject: [PATCH] #231 call init colors only if setTheme() call was successful - this will change app to dark on machines where setTheme() works, but hopefully will not mess up colors on machines where setTheme() has no effect for some reason --- src/net/azib/ipscan/gui/GUI.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/net/azib/ipscan/gui/GUI.java b/src/net/azib/ipscan/gui/GUI.java index 36446171..c2c4e59e 100644 --- a/src/net/azib/ipscan/gui/GUI.java +++ b/src/net/azib/ipscan/gui/GUI.java @@ -13,6 +13,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; +import java.lang.reflect.Method; import java.util.logging.Level; import java.util.logging.Logger; @@ -71,15 +72,17 @@ public class GUI implements AutoCloseable { Boolean isAppDarkAppearance = (Boolean) os.getMethod("isAppDarkAppearance").invoke(null); LOG.info("Dark appearance flags before: " + isDarkMode + ", " + isAppDarkAppearance); if (isDarkMode && !isAppDarkAppearance) { -// os.getMethod("setTheme", boolean.class).invoke(null, isDarkMode); -// isDarkMode = (Boolean) os.getMethod("isSystemDarkAppearance").invoke(null); -// isAppDarkAppearance = (Boolean) os.getMethod("isAppDarkAppearance").invoke(null); -// LOG.info("Dark appearance flags after: " + isDarkMode + ", " + isAppDarkAppearance); - // workaround for a bug in SWT: colors need to be reinited after changing the appearance -// Method initColors = display.getClass().getDeclaredMethod("initColors"); -// initColors.setAccessible(true); -// initColors.invoke(display); - LOG.info("initColors not called"); + os.getMethod("setTheme", boolean.class).invoke(null, isDarkMode); + isDarkMode = (Boolean) os.getMethod("isSystemDarkAppearance").invoke(null); + isAppDarkAppearance = (Boolean) os.getMethod("isAppDarkAppearance").invoke(null); + LOG.info("Dark appearance flags after: " + isDarkMode + ", " + isAppDarkAppearance); + if (isAppDarkAppearance) { + // workaround for a bug in SWT: colors need to be reinited after changing the appearance + Method initColors = display.getClass().getDeclaredMethod("initColors"); + initColors.setAccessible(true); + initColors.invoke(display); + LOG.info("initColors called"); + } } } catch (Exception e) {