From cd0337a2df931622d443cd6297e39df29713bb53 Mon Sep 17 00:00:00 2001 From: Luming Yin Date: Tue, 9 Oct 2018 01:36:15 -0400 Subject: [PATCH] Adopt Dark Mode for screenshot preview --- macOSLucidaGrande/AppDelegate.m | 52 +++++++++++++++--- macOSLucidaGrande/Base.lproj/MainMenu.xib | 2 +- ...iff_10_14.patch => applyDiff_modern.patch} | Bin macOSLucidaGrande/preview_modern_lg_dark.jpg | Bin 0 -> 26470 bytes .../preview_modern_lg_dark@2x.jpg | Bin 0 -> 79965 bytes macOSLucidaGrande/preview_modern_lg_light.jpg | Bin 0 -> 27596 bytes .../preview_modern_lg_light@2x.jpg | Bin 0 -> 82040 bytes macOSLucidaGrande/preview_modern_sf_dark.jpg | Bin 0 -> 26157 bytes .../preview_modern_sf_dark@2x.jpg | Bin 0 -> 79285 bytes macOSLucidaGrande/preview_modern_sf_light.jpg | Bin 0 -> 27237 bytes .../preview_modern_sf_light@2x.jpg | Bin 0 -> 81538 bytes 11 files changed, 45 insertions(+), 9 deletions(-) rename macOSLucidaGrande/{applyDiff_10_14.patch => applyDiff_modern.patch} (100%) create mode 100644 macOSLucidaGrande/preview_modern_lg_dark.jpg create mode 100644 macOSLucidaGrande/preview_modern_lg_dark@2x.jpg create mode 100644 macOSLucidaGrande/preview_modern_lg_light.jpg create mode 100644 macOSLucidaGrande/preview_modern_lg_light@2x.jpg create mode 100644 macOSLucidaGrande/preview_modern_sf_dark.jpg create mode 100644 macOSLucidaGrande/preview_modern_sf_dark@2x.jpg create mode 100644 macOSLucidaGrande/preview_modern_sf_light.jpg create mode 100644 macOSLucidaGrande/preview_modern_sf_light@2x.jpg diff --git a/macOSLucidaGrande/AppDelegate.m b/macOSLucidaGrande/AppDelegate.m index 87a0fcc..22aebe4 100755 --- a/macOSLucidaGrande/AppDelegate.m +++ b/macOSLucidaGrande/AppDelegate.m @@ -9,6 +9,10 @@ #import "AppDelegate.h" #import "NSData+MD5.h" +typedef NS_ENUM(NSUInteger, FontType) { + FontTypeLucidaGrande, + FontTypeSF, +}; @interface AppDelegate () { int versionNumber; @@ -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 *)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]; @@ -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; } } @@ -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 diff --git a/macOSLucidaGrande/Base.lproj/MainMenu.xib b/macOSLucidaGrande/Base.lproj/MainMenu.xib index 995a7f3..eac00de 100755 --- a/macOSLucidaGrande/Base.lproj/MainMenu.xib +++ b/macOSLucidaGrande/Base.lproj/MainMenu.xib @@ -184,7 +184,7 @@ - +