Skip to content

Commit 7d013b8

Browse files
committed
Add a category to tell if we're in dark mode
1 parent ecca785 commit 7d013b8

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

Classes/NSAppearance+PBDarkMode.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// NSAppearance+PBDarkMode.h
3+
// GitX
4+
//
5+
// Created by Etienne on 18/11/2018.
6+
//
7+
8+
#import <Cocoa/Cocoa.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface NSAppearance (PBDarkMode)
13+
- (BOOL)isDarkMode;
14+
@end
15+
16+
@interface NSApplication (PBDarkMode)
17+
- (BOOL)isDarkMode;
18+
@end
19+
20+
NS_ASSUME_NONNULL_END

Classes/NSAppearance+PBDarkMode.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// NSAppearance+PBDarkMode.m
3+
// GitX
4+
//
5+
// Created by Etienne on 18/11/2018.
6+
//
7+
8+
#import "NSAppearance+PBDarkMode.h"
9+
10+
@implementation NSAppearance (PBDarkMode)
11+
12+
- (BOOL)isDarkMode
13+
{
14+
if (@available(macOS 10.14, *)) {
15+
if ([self bestMatchFromAppearancesWithNames:@[NSAppearanceNameDarkAqua, NSAppearanceNameAqua]] == NSAppearanceNameDarkAqua)
16+
return YES;
17+
return NO;
18+
} else {
19+
return NO;
20+
}
21+
}
22+
23+
@end
24+
25+
@implementation NSApplication (PBDarkMode)
26+
27+
- (BOOL)isDarkMode
28+
{
29+
return self.effectiveAppearance.isDarkMode;
30+
}
31+
32+
@end

GitX.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
4D843B401E5E3939004C3A6F /* PBGitRepository_PBGitBinarySupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D843B3F1E5E3939004C3A6F /* PBGitRepository_PBGitBinarySupport.m */; };
145145
4DECFBB21E662962004C3A6F /* ObjectiveGit+PBCategories.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DECFBB11E662962004C3A6F /* ObjectiveGit+PBCategories.m */; };
146146
4DF173E621A1A67C003CD3CE /* MAKVONotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF173E521A1A67A003CD3CE /* MAKVONotificationCenter.m */; };
147+
4DF173E921A1D60A003CD3CE /* NSAppearance+PBDarkMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF173E821A1D60A003CD3CE /* NSAppearance+PBDarkMode.m */; };
147148
50660A551FD6F48A004342B0 /* PBSidebarList.m in Sources */ = {isa = PBXBuildFile; fileRef = 50660A541FD6F48A004342B0 /* PBSidebarList.m */; };
148149
507367411FD1F54E003F73E1 /* PBGitCommitTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 507367401FD1F54E003F73E1 /* PBGitCommitTableViewCell.m */; };
149150
508E268D1FD317FC00CE9FE0 /* PBSidebarTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 508E268C1FD317FC00CE9FE0 /* PBSidebarTableViewCell.m */; };
@@ -575,6 +576,8 @@
575576
4DECFBB11E662962004C3A6F /* ObjectiveGit+PBCategories.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ObjectiveGit+PBCategories.m"; sourceTree = "<group>"; };
576577
4DF173E421A1A679003CD3CE /* MAKVONotificationCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MAKVONotificationCenter.h; path = MAKVONotificationCenter/MAKVONotificationCenter.h; sourceTree = "<group>"; };
577578
4DF173E521A1A67A003CD3CE /* MAKVONotificationCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MAKVONotificationCenter.m; path = MAKVONotificationCenter/MAKVONotificationCenter.m; sourceTree = "<group>"; };
579+
4DF173E721A1D60A003CD3CE /* NSAppearance+PBDarkMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSAppearance+PBDarkMode.h"; sourceTree = "<group>"; };
580+
4DF173E821A1D60A003CD3CE /* NSAppearance+PBDarkMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSAppearance+PBDarkMode.m"; sourceTree = "<group>"; };
578581
50660A531FD6F48A004342B0 /* PBSidebarList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBSidebarList.h; sourceTree = "<group>"; };
579582
50660A541FD6F48A004342B0 /* PBSidebarList.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PBSidebarList.m; sourceTree = "<group>"; };
580583
5073673F1FD1F54E003F73E1 /* PBGitCommitTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBGitCommitTableViewCell.h; sourceTree = "<group>"; };
@@ -875,6 +878,8 @@
875878
4A5D76B314A9A9CC00DF6C68 /* Views */,
876879
4D6E4F781E56851A004C3A6F /* PBMacros.m */,
877880
4D6E4F791E56851A004C3A6F /* PBMacros.h */,
881+
4DF173E721A1D60A003CD3CE /* NSAppearance+PBDarkMode.h */,
882+
4DF173E821A1D60A003CD3CE /* NSAppearance+PBDarkMode.m */,
878883
);
879884
path = Classes;
880885
sourceTree = "<group>";
@@ -1507,6 +1512,7 @@
15071512
507367411FD1F54E003F73E1 /* PBGitCommitTableViewCell.m in Sources */,
15081513
4A5D772B14A9A9CC00DF6C68 /* PBCommitMessageView.m in Sources */,
15091514
4A5D772C14A9A9CC00DF6C68 /* PBCreateBranchSheet.m in Sources */,
1515+
4DF173E921A1D60A003CD3CE /* NSAppearance+PBDarkMode.m in Sources */,
15101516
4A5D772D14A9A9CC00DF6C68 /* PBCreateTagSheet.m in Sources */,
15111517
4A5D772E14A9A9CC00DF6C68 /* PBFileChangesTableView.m in Sources */,
15121518
6C5244131E00C66E0051DE20 /* PBHistorySearchMode.m in Sources */,

Resources/GitX_Prefix.pch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
#import <Cocoa/Cocoa.h>
55
#import <ObjectiveGit/ObjectiveGit.h>
66
#import "MAKVONotificationCenter.h"
7+
#import "NSAppearance+PBDarkMode.h"
78
#import "PBMacros.h"
89
#endif

0 commit comments

Comments
 (0)