From bed2ca26a6b123b0bfb923eba087870bf2017bb6 Mon Sep 17 00:00:00 2001 From: lint <47455468+lint@users.noreply.github.com> Date: Sat, 6 Jun 2020 23:30:53 -0400 Subject: [PATCH] Fix Reddit incorrect text color bug --- tweak/Reddit.h | 6 ++++++ tweak/Reddit.xm | 23 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tweak/Reddit.h b/tweak/Reddit.h index facc6eb..abb18c2 100644 --- a/tweak/Reddit.h +++ b/tweak/Reddit.h @@ -169,6 +169,8 @@ @interface AppSettings + (id)sharedSettings; +- (BOOL)useDarkMode; +- (BOOL)isAutoDarkModeEnabled; @end @interface AccountManager @@ -208,3 +210,7 @@ @interface MarkDownParser + (id)attributedStringFromMarkdownString:(id)arg1; @end + +@interface UITraitCollection () ++ (id)_currentTraitCollection; +@end diff --git a/tweak/Reddit.xm b/tweak/Reddit.xm index 5b2a61a..ec34bb9 100644 --- a/tweak/Reddit.xm +++ b/tweak/Reddit.xm @@ -102,16 +102,31 @@ int secondVersionPart = 0; id textColor; if (firstVersionPart == 2020) { - themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]]; + AppSettings *appSettings = [%c(AppSettings) sharedSettings]; + themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:appSettings]; isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; - if (isNightMode) { - textColor = [[themeManager darkTheme] bodyTextColor]; + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0") && [appSettings isAutoDarkModeEnabled]) { + + NSInteger sysInterfaceStyle = [[UITraitCollection _currentTraitCollection] userInterfaceStyle]; + + if (sysInterfaceStyle == UIUserInterfaceStyleDark){ + textColor = [[themeManager darkTheme] bodyTextColor]; + } else { + textColor = [[themeManager lightTheme] bodyTextColor]; + } + } else { - textColor = [[themeManager lightTheme] bodyTextColor]; + + if (isNightMode) { + textColor = [[themeManager darkTheme] bodyTextColor]; + } else { + textColor = [[themeManager lightTheme] bodyTextColor]; + } } [themeManager release]; + } else { if (secondVersionPart >= 45) {