Skip to content

Commit

Permalink
Merge pull request #1972 from Mailaender/dark-theme-color-check
Browse files Browse the repository at this point in the history
Fixed Dark Mode detection on macOS
  • Loading branch information
eselmeister authored Nov 25, 2024
2 parents 6dba37a + a23537c commit 0dc879a
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2023 Lablicate GmbH.
* Copyright (c) 2017, 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -14,9 +14,14 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.support.settings.OperatingSystemUtils;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

public class PreferencesSupport {
Expand All @@ -36,7 +41,13 @@ public static void cleanPreferencesByNodeId(List<String> preservePreferenceNodes
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=564022
public static boolean isDarkTheme() {

return Platform.getPreferencesService().getString("org.eclipse.e4.ui.css.swt.theme", "themeid", "", null).endsWith("dark");
if(OperatingSystemUtils.isMac()) {
Color background = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
RGB rgb = background.getRGB();
return (rgb.red < 128 && rgb.green < 128 && rgb.blue < 128);
} else {
return Platform.getPreferencesService().getString("org.eclipse.e4.ui.css.swt.theme", "themeid", "", null).endsWith("dark");
}
}

/**
Expand Down

0 comments on commit 0dc879a

Please sign in to comment.