From 1300d0d49e6f4a135f3c2b28181d4e327be75732 Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Sun, 17 May 2020 13:31:26 -0700 Subject: [PATCH] #231 do not change to dark mode programmatically, which may result in distorted colors due to SWT not being able to update the colors correctly. Tell macOS to start the app in dark more automatically using Info.plist - this now works with updated SWT --- .../Angry IP Scanner.app/Contents/Info.plist | 2 ++ src/net/azib/ipscan/gui/GUI.java | 33 ------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/ext/mac-bundle/Angry IP Scanner.app/Contents/Info.plist b/ext/mac-bundle/Angry IP Scanner.app/Contents/Info.plist index c111b24f..2f460f9c 100644 --- a/ext/mac-bundle/Angry IP Scanner.app/Contents/Info.plist +++ b/ext/mac-bundle/Angry IP Scanner.app/Contents/Info.plist @@ -24,5 +24,7 @@ NSApplication NSHighResolutionCapable + NSRequiresAquaSystemAppearance + diff --git a/src/net/azib/ipscan/gui/GUI.java b/src/net/azib/ipscan/gui/GUI.java index bbe7c338..f15c8f82 100644 --- a/src/net/azib/ipscan/gui/GUI.java +++ b/src/net/azib/ipscan/gui/GUI.java @@ -1,7 +1,6 @@ package net.azib.ipscan.gui; import net.azib.ipscan.config.LoggerFactory; -import net.azib.ipscan.config.Platform; import net.azib.ipscan.config.Version; import net.azib.ipscan.core.UserErrorException; import net.azib.ipscan.di.Injector; @@ -13,7 +12,6 @@ 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; @@ -43,7 +41,6 @@ public class GUI implements AutoCloseable { public void showMainWindow(Injector injector) { mainWindow = injector.require(MainWindow.class); - if (Platform.MAC_OS) setMacDarkAppearanceIfNeeded(); LOG.fine("Main window created: " + (System.currentTimeMillis() - startTime)); @@ -63,36 +60,6 @@ public class GUI implements AutoCloseable { } } - private void setMacDarkAppearanceIfNeeded() { - try { - // changing the appearance works only after the shell has been created - Class os = Class.forName("org.eclipse.swt.internal.cocoa.OS"); - Boolean isDarkMode = (Boolean) os.getMethod("isSystemDarkAppearance").invoke(null); - 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, true); - 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"); - } - else { - os.getMethod("setTheme", boolean.class).invoke(null, false); - LOG.info("Dark appearance reset back because it didn't work"); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - public void showMessage(int flags, String title, String localizedMessage) { Shell parent = Display.getDefault().getActiveShell(); if (parent == null && mainWindow != null) parent = mainWindow.getShell();