Showing release notes with dark appearance according to the system theme.

This is done by applying a user stylesheet, making the background of the WebView transparent, and using a NSBox to display the dynamic dark background color. The appearance of the release notes will unfortunately not adapt if the theme is changed while the release notes window is open.
This commit is contained in:
Michel Fortin committed 2018-08-26 11:51:10 -04:00
1 parent e40628a78f
commit 64eb13672d
3 files changed
+62 -2

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
html {
color: white;
background: transparent;
}
:link {
color: #419CFF;
}
:link:active {
color: #FF1919;
}
+6 -2
View File
@@ -43,6 +43,7 @@
14950073195FCE4E00BC5B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; };
14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6B19AEBC530061B14F /* signed-test-file.txt */; };
14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6C19AEBC610061B14F /* test-pubkey.pem */; };
1EAA4C8B2132C7BF00604473 /* DarkAqua.css in Resources */ = {isa = PBXBuildFile; fileRef = 1EAA4C8A2132C7BF00604473 /* DarkAqua.css */; };
3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
55C14BEF136EF21700649790 /* SUStatus.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C14BD8136EF00C00649790 /* SUStatus.xib */; };
55C14C04136EF26100649790 /* SUUpdateAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C14BF0136EF26100649790 /* SUUpdateAlert.xib */; };
@@ -810,6 +811,7 @@
1A985A511C5C32BB0001163A /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1A985A521C5C32BC0001163A /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1A985A531C5C32BD0001163A /* el */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = el; path = el.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1EAA4C8A2132C7BF00604473 /* DarkAqua.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = DarkAqua.css; sourceTree = "<group>"; };
3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUVersionDisplayProtocol.h; sourceTree = "<group>"; };
4607BEA21948443800EF8DA4 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/Sparkle.strings; sourceTree = "<group>"; };
4607BEA41948443800EF8DA4 /* nb */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = nb; path = nb.lproj/SUUpdateAlert.xib; sourceTree = "<group>"; };
@@ -1489,6 +1491,7 @@
14732BBC1960EFB500593899 /* README.markdown */,
14732BB91960EEEE00593899 /* SampleAppcast.xml */,
615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */,
1EAA4C8A2132C7BF00604473 /* DarkAqua.css */,
);
path = Resources;
sourceTree = "<group>";
@@ -2524,13 +2527,13 @@
};
726E07AC1CAF08D6001A286B = {
CreatedOnToolsVersion = 7.3;
};
};
726E07EE1CAF37BD001A286B = {
CreatedOnToolsVersion = 7.3;
SystemCapabilities = {
com.apple.Sandbox = {
enabled = 1;
};
};
};
};
726E4A151C86C88F00C57C6A = {
@@ -2732,6 +2735,7 @@
buildActionMask = 2147483647;
files = (
61AAE8280A321A7F00D8810D /* Sparkle.strings in Resources */,
1EAA4C8B2132C7BF00604473 /* DarkAqua.css in Resources */,
615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */,
55C14BEF136EF21700649790 /* SUStatus.xib in Resources */,
55C14C04136EF26100649790 /* SUUpdateAlert.xib in Resources */,
+46
View File
@@ -58,6 +58,8 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
@property (weak) IBOutlet NSButton *skipButton;
@property (weak) IBOutlet NSButton *laterButton;
@property (strong) NSBox *darkBackgroundView;
@end
@implementation SUUpdateAlert
@@ -83,6 +85,8 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
@synthesize skipButton;
@synthesize laterButton;
@synthesize darkBackgroundView = _darkBackgroundView;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id <SUVersionDisplay>)aVersionDisplayer
{
self = [super initWithWindowNibName:@"SUUpdateAlert"];
@@ -214,6 +218,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
// "-apple-system-font" is a reference to the system UI font. "-apple-system" is the new recommended token, but for backward compatibility we can't use it.
prefs.standardFontFamily = @"-apple-system-font";
prefs.defaultFontSize = (int)[NSFont systemFontSize];
[self adaptReleaseNotesAppearance];
// Stick a nice big spinner in the middle of the web view until the page is loaded.
NSRect frame = [[self.releaseNotesView superview] frame];
@@ -231,6 +236,47 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
}
}
- (void)adaptReleaseNotesAppearance
{
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 10.14, *))
{
WebPreferences *prefs = [self.releaseNotesView preferences];
if ([self.releaseNotesView effectiveAppearance].name == NSAppearanceNameDarkAqua || [self.releaseNotesView effectiveAppearance].name == NSAppearanceNameAccessibilityHighContrastDarkAqua)
{
// Set user stylesheet adapted to light on dark
prefs.userStyleSheetEnabled = YES;
prefs.userStyleSheetLocation = [[NSBundle bundleForClass:[self class]] URLForResource:@"DarkAqua" withExtension:@"css"];
// Remove web view background...
self.releaseNotesView.drawsBackground = NO;
// ... and use NSBox to get the dynamically colored background
if (self.darkBackgroundView == nil)
{
self.darkBackgroundView = [[NSBox alloc] initWithFrame:self.releaseNotesView.frame];
self.darkBackgroundView.boxType = NSBoxCustom;
self.darkBackgroundView.fillColor = [NSColor textBackgroundColor];
self.darkBackgroundView.borderColor = [NSColor clearColor];
// Using auto-resizing mask instead of contraints works well enough
self.darkBackgroundView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self.releaseNotesView.superview addSubview:self.darkBackgroundView positioned:NSWindowBelow relativeTo:self.releaseNotesView];
// The release note user stylesheet will not adjust to the user changing the theme until adaptReleaseNoteAppearance is called again.
// So lock the appearance of the background to keep the text readable if the system theme changes.
self.darkBackgroundView.appearance = self.darkBackgroundView.effectiveAppearance;
}
}
else
{
// Restore standard dark on light appearance
[self.darkBackgroundView removeFromSuperview];
prefs.userStyleSheetEnabled = NO;
self.releaseNotesView.drawsBackground = YES;
}
}
#endif
}
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
{
if (!self.webViewFinishedLoading) {