29
29
// More info at <https://github.com/sequelpro/sequelpro>
30
30
31
31
#import " SPAboutController.h"
32
+ #import " SPOSInfo.h"
32
33
33
34
static NSString *SPSnapshotBuildIndicator = @" Snapshot" ;
34
35
38
39
static NSString *SPAboutPanelNibName = @" AboutPanel" ;
39
40
static NSString *SPShortVersionHashKey = @" SPVersionShortHash" ;
40
41
42
+ static BOOL isOSAtLeast10_14 = NO ;
43
+
41
44
@interface SPAboutController ()
42
45
46
+ - (BOOL )_isInDarkMode ;
43
47
- (void )_setVersionLabel : (BOOL )isNightly ;
48
+ - (NSAttributedString *)_getCreditsText ;
49
+ - (NSAttributedString *)_getLicenseText ;
50
+ - (NSAttributedString *)_applyTextAttributes : (NSMutableAttributedString *)text ;
44
51
45
52
@end
46
53
47
54
@implementation SPAboutController
48
55
49
56
#pragma mark -
50
57
58
+ + (void )initialize
59
+ {
60
+ isOSAtLeast10_14 = [SPOSInfo isOSVersionAtLeastMajor: 10 minor: 14 patch: 0 ];
61
+ }
62
+
51
63
- (id )init
52
64
{
53
65
return [super initWithWindowNibName: SPAboutPanelNibName];
@@ -59,24 +71,19 @@ - (void)awakeFromNib
59
71
60
72
// If the version string has a prefix of 'Nightly' then this is obviously a nighly build.
61
73
NSRange matchRange = [version rangeOfString: SPSnapshotBuildIndicator];
62
- BOOL isSnapshotBuild = (matchRange.location != NSNotFound );
74
+
75
+ BOOL isSnapshotBuild = matchRange.location != NSNotFound ;
63
76
64
77
// Set the application name, but only include the major version if this is not a nightly build.
65
78
[appNameVersionTextField setStringValue: isSnapshotBuild ? @" Sequel Pro" : [NSString stringWithFormat: @" Sequel Pro %@ " , version]];
66
79
67
80
[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 ];
74
81
75
82
// Set the credits
76
- [[appCreditsTextView textStorage ] appendAttributedString: credits ];
83
+ [[appCreditsTextView textStorage ] appendAttributedString: [ self _getCreditsText ] ];
77
84
78
85
// Set the license
79
- [[appLicenseTextView textStorage ] appendAttributedString: license ];
86
+ [[appLicenseTextView textStorage ] appendAttributedString: [ self _getLicenseText ] ];
80
87
}
81
88
82
89
#pragma mark -
@@ -102,6 +109,19 @@ - (IBAction)closeApplicationLicenseSheet:(id)sender;
102
109
#pragma mark -
103
110
#pragma mark Private API
104
111
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
+
105
125
/* *
106
126
* Set the UI version labels.
107
127
*
@@ -133,4 +153,36 @@ - (void)_setVersionLabel:(BOOL)isSnapshotBuild
133
153
[appBuildVersionTextField setStringValue: textFieldString];
134
154
}
135
155
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
+
136
188
@end
0 commit comments