Skip to content

Commit c1675de

Browse files
committed
#2485: Fix display of credits and license text in about dialog when dark mode is in use.
1 parent d437b40 commit c1675de

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

Source/SPAboutController.m

+61-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// More info at <https://github.com/sequelpro/sequelpro>
3030

3131
#import "SPAboutController.h"
32+
#import "SPOSInfo.h"
3233

3334
static NSString *SPSnapshotBuildIndicator = @"Snapshot";
3435

@@ -38,16 +39,27 @@
3839
static NSString *SPAboutPanelNibName = @"AboutPanel";
3940
static NSString *SPShortVersionHashKey = @"SPVersionShortHash";
4041

42+
static BOOL isOSAtLeast10_14 = NO;
43+
4144
@interface SPAboutController ()
4245

46+
- (BOOL)_isInDarkMode;
4347
- (void)_setVersionLabel:(BOOL)isNightly;
48+
- (NSAttributedString *)_getCreditsText;
49+
- (NSAttributedString *)_getLicenseText;
50+
- (NSAttributedString *)_applyTextAttributes:(NSMutableAttributedString *)text;
4451

4552
@end
4653

4754
@implementation SPAboutController
4855

4956
#pragma mark -
5057

58+
+ (void)initialize
59+
{
60+
isOSAtLeast10_14 = [SPOSInfo isOSVersionAtLeastMajor:10 minor:14 patch:0];
61+
}
62+
5163
- (id)init
5264
{
5365
return [super initWithWindowNibName:SPAboutPanelNibName];
@@ -59,24 +71,19 @@ - (void)awakeFromNib
5971

6072
// If the version string has a prefix of 'Nightly' then this is obviously a nighly build.
6173
NSRange matchRange = [version rangeOfString:SPSnapshotBuildIndicator];
62-
BOOL isSnapshotBuild = (matchRange.location != NSNotFound);
74+
75+
BOOL isSnapshotBuild = matchRange.location != NSNotFound;
6376

6477
// Set the application name, but only include the major version if this is not a nightly build.
6578
[appNameVersionTextField setStringValue:isSnapshotBuild ? @"Sequel Pro" : [NSString stringWithFormat:@"Sequel Pro %@", version]];
6679

6780
[self _setVersionLabel:isSnapshotBuild];
68-
69-
// Get the credits file contents
70-
NSAttributedString *credits = [[[NSAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:SPCreditsFilename ofType:@"rtf"] documentAttributes:nil] autorelease];
71-
72-
// Get the license file contents
73-
NSAttributedString *license = [[[NSAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:SPLicenseFilename ofType:@"rtf"] documentAttributes:nil] autorelease];
7481

7582
// Set the credits
76-
[[appCreditsTextView textStorage] appendAttributedString:credits];
83+
[[appCreditsTextView textStorage] appendAttributedString:[self _getCreditsText]];
7784

7885
// Set the license
79-
[[appLicenseTextView textStorage] appendAttributedString:license];
86+
[[appLicenseTextView textStorage] appendAttributedString:[self _getLicenseText]];
8087
}
8188

8289
#pragma mark -
@@ -102,6 +109,19 @@ - (IBAction)closeApplicationLicenseSheet:(id)sender;
102109
#pragma mark -
103110
#pragma mark Private API
104111

112+
- (BOOL)_isInDarkMode
113+
{
114+
if (isOSAtLeast10_14) {
115+
NSString *match = [[NSAppearance currentAppearance] bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
116+
117+
if ([NSAppearanceNameDarkAqua isEqualToString:match]) {
118+
return YES;
119+
}
120+
}
121+
122+
return NO;
123+
}
124+
105125
/**
106126
* Set the UI version labels.
107127
*
@@ -133,4 +153,36 @@ - (void)_setVersionLabel:(BOOL)isSnapshotBuild
133153
[appBuildVersionTextField setStringValue:textFieldString];
134154
}
135155

156+
/**
157+
* Returns the credits string to display in the about dialog.
158+
*/
159+
- (NSAttributedString *)_getCreditsText
160+
{
161+
NSMutableAttributedString *credits = [[NSMutableAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:SPCreditsFilename ofType:@"rtf"] documentAttributes:nil];
162+
163+
return [[self _applyTextAttributes:credits] autorelease];
164+
}
165+
166+
/**
167+
* Returns the license string to display in the about dialog.
168+
*/
169+
- (NSAttributedString *)_getLicenseText
170+
{
171+
NSMutableAttributedString *license = [[NSMutableAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:SPLicenseFilename ofType:@"rtf"] documentAttributes:nil];
172+
173+
return [[self _applyTextAttributes:license] autorelease];
174+
}
175+
176+
/**
177+
*
178+
*/
179+
- (NSAttributedString *)_applyTextAttributes:(NSMutableAttributedString *)text
180+
{
181+
if ([self _isInDarkMode]) {
182+
[text addAttribute:NSForegroundColorAttributeName value:[NSColor textColor] range:NSMakeRange(0, [text length])];
183+
}
184+
185+
return text;
186+
}
187+
136188
@end

0 commit comments

Comments
 (0)