From 3ed5f3875bed1e66e1c29319f74d745aab7764b5 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Sat, 15 Sep 2018 09:45:54 -0400 Subject: [PATCH 1/3] React to effective appearance changing. --- Sparkle/SUUpdateAlert.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 057379fa..192bb105 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -219,6 +219,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE prefs.standardFontFamily = @"-apple-system-font"; prefs.defaultFontSize = (int)[NSFont systemFontSize]; [self adaptReleaseNotesAppearance]; + [self.releaseNotesView addObserver:self forKeyPath:@"effectiveAppearance" options:0 context:nil]; // Stick a nice big spinner in the middle of the web view until the page is loaded. NSRect frame = [[self.releaseNotesView superview] frame]; @@ -236,6 +237,16 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE } } +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(__attribute__((unused)) NSDictionary *)change context:(__attribute__((unused)) void *)context { + if (object == self.releaseNotesView && [keyPath isEqualToString:@"effectiveAppearance"]) { + [self adaptReleaseNotesAppearance]; + } +} + +- (void)dealloc { + [self.releaseNotesView removeObserver:self forKeyPath:@"effectiveAppearance"]; +} + - (void)adaptReleaseNotesAppearance { #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 From 077e2b155fd2aa4810678f3b30b0f4c6388738c7 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Sat, 15 Sep 2018 09:47:37 -0400 Subject: [PATCH 2/3] Avoid checking appearance by name, use bestMatchFromAppearancesWithNames for future-proofing. --- Sparkle/SUUpdateAlert.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 192bb105..113fb2a7 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -253,7 +253,8 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE if (@available(macOS 10.14, *)) { WebPreferences *prefs = [self.releaseNotesView preferences]; - if ([self.releaseNotesView effectiveAppearance].name == NSAppearanceNameDarkAqua || [self.releaseNotesView effectiveAppearance].name == NSAppearanceNameAccessibilityHighContrastDarkAqua) + NSAppearanceName bestAppearance = [self.releaseNotesView.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; + if ([bestAppearance isEqualToString:NSAppearanceNameDarkAqua]) { // Set user stylesheet adapted to light on dark prefs.userStyleSheetEnabled = YES; From 20d5b4e0031d81f69c64179c7180d166cd27ee5c Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Sat, 15 Sep 2018 09:59:47 -0400 Subject: [PATCH 3/3] Setting `darkBackgroundView` to nil when adapting for light mode so it gets recreated later if we re-enter dark mode. --- Sparkle/SUUpdateAlert.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 113fb2a7..55dcdfc2 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -282,6 +282,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE { // Restore standard dark on light appearance [self.darkBackgroundView removeFromSuperview]; + self.darkBackgroundView = nil; prefs.userStyleSheetEnabled = NO; self.releaseNotesView.drawsBackground = YES; }