@@ -93,6 +93,7 @@ + (void)initialize {
93
93
kUserDefaultsKey_FirstLaunch : @(YES ),
94
94
kUserDefaultsKey_DiffWhitespaceMode : @(kGCLiveRepositoryDiffWhitespaceMode_Normal ),
95
95
kUserDefaultsKey_ShowWelcomeWindow : @(YES ),
96
+ kUserDefaultsKey_Theme : kTheme_SystemPreference ,
96
97
};
97
98
[[NSUserDefaults standardUserDefaults ] registerDefaults: defaults];
98
99
}
@@ -265,6 +266,15 @@ - (void)awakeFromNib {
265
266
}
266
267
267
268
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (_willShowRecentPopUpMenu: ) name: NSPopUpButtonWillPopUpNotification object: _recentPopUpButton];
269
+
270
+ NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
271
+ [self _applyTheme: theme];
272
+ [_themePopUpButton.menu removeAllItems ];
273
+ for (NSString * string in [self _themePreferences ]) {
274
+ NSMenuItem * item = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(string, nil ) action: NULL keyEquivalent: @" " ];
275
+ item.representedObject = string;
276
+ [_themePopUpButton.menu addItem: item];
277
+ }
268
278
}
269
279
270
280
- (void )_updatePreferencePanel {
@@ -277,6 +287,16 @@ - (void)_updatePreferencePanel {
277
287
}
278
288
}
279
289
290
+ - (void )_updateThemePopUpButton {
291
+ NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
292
+ for (NSMenuItem * item in _themePopUpButton.menu .itemArray ) {
293
+ if ([item.representedObject isEqualToString: theme]) {
294
+ [_themePopUpButton selectItem: item];
295
+ break ;
296
+ }
297
+ }
298
+ }
299
+
280
300
- (void )_showNotificationWithTitle : (NSString *)title action : (SEL )action message : (NSString *)format , ... NS_FORMAT_FUNCTION(3 , 4 ) {
281
301
NSUserNotification * notification = [[NSUserNotification alloc ] init ];
282
302
if (action) {
@@ -397,6 +417,10 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
397
417
XLOG_DEBUG_UNREACHABLE ();
398
418
}
399
419
420
+ // Load theme preference
421
+ NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
422
+ [self _applyTheme: theme];
423
+
400
424
#if __ENABLE_SUDDEN_TERMINATION__
401
425
// Enable sudden termination
402
426
[[NSProcessInfo processInfo ] enableSuddenTermination ];
@@ -515,6 +539,33 @@ - (IBAction)changeReleaseChannel:(id)sender {
515
539
}
516
540
}
517
541
542
+ - (NSArray *)_themePreferences {
543
+ return @[ kTheme_SystemPreference , kTheme_Dark , kTheme_Light ];
544
+ }
545
+
546
+ - (void )_applyTheme : (NSString *)theme {
547
+ if (@available (macOS 10.14 , *)) {
548
+ NSInteger index = [[self _themePreferences ] indexOfObject: theme];
549
+ switch (index) {
550
+ case 0 :
551
+ NSApp .appearance = nil ;
552
+ break ;
553
+ case 1 :
554
+ NSApp .appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua ];
555
+ break ;
556
+ case 2 :
557
+ NSApp .appearance = [NSAppearance appearanceNamed: NSAppearanceNameAqua ];
558
+ break ;
559
+ }
560
+ }
561
+ [[NSUserDefaults standardUserDefaults ] setObject: theme forKey: kUserDefaultsKey_Theme ];
562
+ }
563
+
564
+ - (IBAction )changeTheme : (id )sender {
565
+ NSString * theme = _themePopUpButton.selectedItem .representedObject ;
566
+ [self _applyTheme: theme];
567
+ }
568
+
518
569
- (IBAction )viewWiki : (id )sender {
519
570
[[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: kURL_Wiki ]];
520
571
}
@@ -543,6 +594,7 @@ - (IBAction)showAboutPanel:(id)sender {
543
594
544
595
- (IBAction )showPreferences : (id )sender {
545
596
[self _updatePreferencePanel ];
597
+ [self _updateThemePopUpButton ];
546
598
[_preferencesWindow makeKeyAndOrderFront: nil ];
547
599
}
548
600
0 commit comments