yousseb / meld

Meld for macOS
https://yousseb.github.io/meld/
GNU General Public License v2.0
2.28k stars 119 forks source link

Use NSApplication effectiveAppearance to determine dark mode #111

Open jan2000 opened 4 years ago

jan2000 commented 4 years ago

Meld does not correctly check dark mode, it should be checked against NSApplication effectiveAppearance. This way one can turn off dark mode per application. Basically the same bug as: https://bugzilla.mozilla.org/show_bug.cgi?id=1593390

Patch based on patch the patch attached to the bugzilla bug: https://phabricator.services.mozilla.com/D51947 (however missing the OnMojaveOrLater and bestMatchFromAppearancesWithNames part):

--- /Applications/Meld.app/Contents/Resources/meld-org  2020-06-04 20:00:10.000000000 +0200
+++ /Applications/Meld.app/Contents/Resources/meld  2020-06-04 20:00:54.000000000 +0200
@@ -44,9 +44,8 @@
 gtk_theme= os.environ.get('GTK_THEME')
 if gtk_theme is None:
     try:
-        from Foundation import NSUserDefaults
-        standardUserDefaults = NSUserDefaults.standardUserDefaults()
-        if standardUserDefaults.stringForKey_("AppleInterfaceStyle") == 'Dark':
+        from Cocoa import NSApplication
+        if NSApplication.sharedApplication().effectiveAppearance().name() == "NSAppearanceNameDarkAqua":
             os.environ['GTK_THEME'] = "Meld-Os-Catalina-gtk:dark"
         else:
             os.environ['GTK_THEME'] = "Meld-Os-Catalina-gtk:light"

With this above patch one can turn dark mode off for Meld:

defaults write org.gnome.meld NSRequiresAquaSystemAppearance -bool yes

Turn back on with:

defaults delete org.gnome.meld NSRequiresAquaSystemAppearance