Skip to content

Commit 3e739d8

Browse files
committed
Toggling between light and dark mode changes request and response formatted windows. Save separate preferences for regular theme and dark theme
1 parent 7b9c1fc commit 3e739d8

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

CRCconstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ FOUNDATION_EXPORT NSString * const RAW_REQUEST_BODY;
1919
FOUNDATION_EXPORT NSString * const RESPONSE_TIMEOUT;
2020
FOUNDATION_EXPORT NSString * const SAVED_DRAWER_SIZE;
2121
FOUNDATION_EXPORT NSString * const THEME;
22+
FOUNDATION_EXPORT NSString * const DARK_THEME;
2223
FOUNDATION_EXPORT NSUInteger const DEFAULT_FONT_SIZE;
2324
FOUNDATION_EXPORT NSString * const SHOW_LINE_NUMBERS;
2425
FOUNDATION_EXPORT NSString * const DISABLE_ANIMATIONS;

CRCconstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ @implementation CRCConstants
1717
NSString * const RESPONSE_TIMEOUT = @"responseTimeout";
1818
NSString * const SAVED_DRAWER_SIZE = @"savedDrawerSize";
1919
NSString * const THEME = @"theme";
20+
NSString * const DARK_THEME = @"darkTheme";
2021
NSUInteger const DEFAULT_FONT_SIZE = 12;
2122
NSString * const SHOW_LINE_NUMBERS = @"showLineNumbers";
2223
NSString * const DISABLE_ANIMATIONS = @"UIDisableAnimations";

core/CocoaRestClientAppDelegate.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,12 @@ - (IBAction) themeMenuItemSelected:(id)sender {
659659
[((MainWindowController *)mainWindowController).requestView setTheme:[sender tag]];
660660
}
661661

662-
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInteger:[sender tag]] forKey:THEME];
662+
NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
663+
if ([osxMode isEqualToString:@"Dark"]) {
664+
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInteger:[sender tag]] forKey:DARK_THEME];
665+
} else {
666+
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInteger:[sender tag]] forKey:THEME];
667+
}
663668

664669
// Unselect all theme MenuItems
665670
NSMenuItem *themeMenu = [((NSMenuItem *) sender) parentItem];

core/MainWindowController.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,19 @@ - (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTou
204204
}
205205

206206
-(void) initHighlightedViews {
207-
ACETheme aceTheme = [[NSUserDefaults standardUserDefaults] integerForKey:THEME];
207+
NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
208+
ACETheme aceTheme;
209+
if ([osxMode isEqualToString:@"Dark"]) {
210+
aceTheme = [[NSUserDefaults standardUserDefaults] integerForKey:DARK_THEME];
211+
if (! aceTheme) {
212+
aceTheme = ACEThemeTomorrowNightEighties;
213+
}
214+
} else {
215+
aceTheme = [[NSUserDefaults standardUserDefaults] integerForKey:THEME];
216+
if (! aceTheme) {
217+
aceTheme = ACEThemeChrome;
218+
}
219+
}
208220
[[[self.appDelegate.themeMenuItem submenu] itemWithTag:aceTheme] setState:NSOnState];
209221

210222
self.appDelegate.aceViewFontSize = 12;
@@ -991,15 +1003,26 @@ - (void)syntaxHighlightingPreferenceChanged {
9911003

9921004
- (void)darkModeChanged:(id)sender {
9931005
NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
1006+
ACETheme aceTheme;
9941007
if ([osxMode isEqualToString:@"Dark"]) {
9951008
self.submitButton.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
9961009
self.urlBox.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
9971010
self.methodButton.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
1011+
aceTheme = [[NSUserDefaults standardUserDefaults] integerForKey:DARK_THEME];
1012+
if (! aceTheme) {
1013+
aceTheme = ACEThemeTomorrowNightEighties;
1014+
}
9981015
} else {
9991016
self.submitButton.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
10001017
self.urlBox.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
10011018
self.methodButton.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
1019+
aceTheme = [[NSUserDefaults standardUserDefaults] integerForKey:THEME];
1020+
if (! aceTheme) {
1021+
aceTheme = ACEThemeChrome;
1022+
}
10021023
}
1024+
[self.responseView setTheme:aceTheme];
1025+
[self.requestView setTheme:aceTheme];
10031026
}
10041027

10051028
#pragma mark -

0 commit comments

Comments
 (0)