Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Adopt Dark Mode for screenshot preview
Browse files Browse the repository at this point in the history
  • Loading branch information
LumingYin committed Oct 9, 2018
1 parent 77218e9 commit cd0337a
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 9 deletions.
52 changes: 44 additions & 8 deletions macOSLucidaGrande/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#import "AppDelegate.h"
#import "NSData+MD5.h"

typedef NS_ENUM(NSUInteger, FontType) {
FontTypeLucidaGrande,
FontTypeSF,
};

@interface AppDelegate () {
int versionNumber;
Expand Down Expand Up @@ -80,20 +84,52 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification {
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self checkForUpdates];
alreadyCheckedUpdate = YES;
[self.window addObserver:self forKeyPath:@"effectiveAppearance" options:NSKeyValueObservingOptionNew context:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"effectiveAppearance"] && _fontSelector != nil) {
[self segmentedControlChanged:_fontSelector];
}
}


- (void)showLGPreview {
[_fontSelector setSelected:NO forSegment:0];
[_fontSelector setSelected:YES forSegment:1];
_previewImage.image = [NSImage imageNamed:@"preview_lg"];
[self updatePreviewImage:FontTypeLucidaGrande];
}

- (void)showSFPreview {
[_fontSelector setSelected:NO forSegment:1];
[_fontSelector setSelected:YES forSegment:0];
_previewImage.image = [NSImage imageNamed:@"preview_sf"];
[self updatePreviewImage:FontTypeSF];
}

- (void)updatePreviewImage:(FontType)fontType {
if (@available(macOS 10.14, *)) {
NSAppearanceName name = [self.window.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
if (name == NSAppearanceNameDarkAqua) {
if (fontType == FontTypeLucidaGrande) {
_previewImage.image = [NSImage imageNamed:@"preview_modern_lg_dark"];
} else if (fontType == FontTypeSF) {
_previewImage.image = [NSImage imageNamed:@"preview_modern_sf_dark"];
}
} else {
if (fontType == FontTypeLucidaGrande) {
_previewImage.image = [NSImage imageNamed:@"preview_modern_lg_light"];
} else if (fontType == FontTypeSF) {
_previewImage.image = [NSImage imageNamed:@"preview_modern_sf_light"];
}
}
} else {
if (fontType == FontTypeLucidaGrande) {
_previewImage.image = [NSImage imageNamed:@"preview_lg"];
} else if (fontType == FontTypeSF) {
_previewImage.image = [NSImage imageNamed:@"preview_sf"];
}
}
}

- (void)refreshStatus{
[self cleanOldPatch];
Expand All @@ -118,16 +154,16 @@ - (void)refreshStatus{

- (IBAction)segmentedControlChanged:(NSSegmentedControl *)sender {
if (latestPatchPresent && sender.selectedSegment == 0) {
_previewImage.image = [NSImage imageNamed:@"preview_sf"];
[self updatePreviewImage:FontTypeSF];
_callToActionBtn.hidden = NO;
} else if (latestPatchPresent && sender.selectedSegment == 1) {
_previewImage.image = [NSImage imageNamed:@"preview_lg"];
[self updatePreviewImage:FontTypeLucidaGrande];
_callToActionBtn.hidden = YES;
} else if (!latestPatchPresent && sender.selectedSegment == 0) {
_previewImage.image = [NSImage imageNamed:@"preview_sf"];
[self updatePreviewImage:FontTypeSF];
_callToActionBtn.hidden = YES;
} else if (!latestPatchPresent && sender.selectedSegment == 1) {
_previewImage.image = [NSImage imageNamed:@"preview_lg"];
[self updatePreviewImage:FontTypeLucidaGrande];
_callToActionBtn.hidden = NO;
}
}
Expand Down Expand Up @@ -245,9 +281,9 @@ - (IBAction)useFont:(id)sender {
// Fetches the URL of Lucida Grande font that poses San Francisco
NSString *nameOfPatchFile;
if (versionNumber > 13) {
nameOfPatchFile = [NSString stringWithFormat:@"applyDiff_10_%d", versionNumber];
nameOfPatchFile = @"applyDiff_modern";
} else {
nameOfPatchFile = @"applyDiff_10_13";
nameOfPatchFile = [NSString stringWithFormat:@"applyDiff_10_%d", versionNumber];
}
NSString *diffPath = [[NSBundle mainBundle] pathForResource:nameOfPatchFile ofType:@"patch"];
// Copies the Lucida Grande font over to the desired installation location
Expand Down
2 changes: 1 addition & 1 deletion macOSLucidaGrande/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
</textField>
</subviews>
</view>
<color key="fillColor" red="0.0" green="0.0" blue="0.0" alpha="0.42256272010000001" colorSpace="custom" customColorSpace="displayP3"/>
<color key="fillColor" red="0.0" green="0.0" blue="0.0" alpha="0.91133912852112675" colorSpace="custom" customColorSpace="displayP3"/>
</box>
<button hidden="YES" verticalHuggingPriority="750" id="HKN-7f-EFy">
<rect key="frame" x="397" y="59" width="37" height="37"/>
Expand Down
Binary file added macOSLucidaGrande/preview_modern_lg_dark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added macOSLucidaGrande/preview_modern_lg_dark@2x.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added macOSLucidaGrande/preview_modern_lg_light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added macOSLucidaGrande/preview_modern_lg_light@2x.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added macOSLucidaGrande/preview_modern_sf_dark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added macOSLucidaGrande/preview_modern_sf_dark@2x.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added macOSLucidaGrande/preview_modern_sf_light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added macOSLucidaGrande/preview_modern_sf_light@2x.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cd0337a

Please sign in to comment.