Skip to content

Commit

Permalink
Merge pull request #263 from Automattic/fix/mojave-theme-default-setting
Browse files Browse the repository at this point in the history
Allow user to reset to system appearance setting
  • Loading branch information
roundhill authored Oct 26, 2018
2 parents 500f569 + 60e11f1 commit d80658e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions DB5/VSThemeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ extern NSString *const VSThemeManagerThemePrefKey;

- (void)swapTheme:(NSString *)theme;
- (BOOL)isDarkMode;
- (BOOL)isMojaveWithNoThemeSet;

@end
8 changes: 8 additions & 0 deletions DB5/VSThemeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ - (BOOL)isDarkMode {
return isDarkTheme;
}

- (BOOL)isMojaveWithNoThemeSet {
if (@available(macOS 10.14, *)) {
return [[NSUserDefaults standardUserDefaults] stringForKey:VSThemeManagerThemePrefKey] == nil;
}

return NO;
}

@end
4 changes: 2 additions & 2 deletions Simplenote/Simplenote-Info-Hockey.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.8</string>
<string>1.3.9</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -38,7 +38,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1382</string>
<string>1390</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 2 additions & 2 deletions Simplenote/Simplenote-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.8</string>
<string>1.3.9</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -38,7 +38,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1382</string>
<string>1390</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
36 changes: 31 additions & 5 deletions Simplenote/SimplenoteAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define kFirstLaunchKey @"SPFirstLaunch"
#define kMinimumNoteListSplit 240
#define kMaximumNoteListSplit 384
#define kDefaultThemeAppearanceTag 2


#pragma mark ====================================================================================
Expand Down Expand Up @@ -167,7 +168,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[self configureWindow];
[self hookWindowNotifications];

[self updateThemeMenuForPosition:[[VSThemeManager sharedManager] isDarkMode] ? 1 : 0];
VSThemeManager *themeManager = [VSThemeManager sharedManager];
if ([themeManager isMojaveWithNoThemeSet]) {
[self updateThemeMenuForPosition:kDefaultThemeAppearanceTag];
} else {
[self updateThemeMenuForPosition:[[VSThemeManager sharedManager] isDarkMode] ? 1 : 0];
}
[self applyStyle];

self.simperium = [self configureSimperium];
Expand Down Expand Up @@ -229,6 +235,16 @@ - (void)configureWindow
[self.textViewParent addSubview:markdownView];
self.noteEditorViewController.markdownView = markdownView;
[markdownView setNavigationDelegate:self.noteEditorViewController];

// Add the System Appearance menu item to the 'Theme' menu on Mojave or later
if (@available(macOS 10.14, *)) {
NSMenuItem *separatorItem = [NSMenuItem separatorItem];
[themeMenu addItem:separatorItem];

NSMenuItem *systemDefaultItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"System Appearance", @"Menu item for using default macOS theme appearance.") action:@selector(changeThemeAction:) keyEquivalent:@""];
systemDefaultItem.tag = kDefaultThemeAppearanceTag;
[themeMenu addItem:systemDefaultItem];
}

[self configureToolbar];
}
Expand Down Expand Up @@ -768,11 +784,21 @@ - (IBAction)changeThemeAction:(id)sender
if (item.state == NSOnState) {
return;
}

NSString *newTheme = ([sender tag] == 0) ? @"default" : @"dark";

[SPTracker trackSettingsThemeUpdated:newTheme];
[[VSThemeManager sharedManager] swapTheme:newTheme];
if ([sender tag] == kDefaultThemeAppearanceTag) {
// Resetting to default macOS theme appearance
[[NSUserDefaults standardUserDefaults] removeObjectForKey:VSThemeManagerThemePrefKey];
if (@available(macOS 10.14, *)) {
SPWindow *window = (SPWindow *)self.window;
window.appearance = nil;
[window applyMojaveThemeOverrideIfNecessary];
}
} else {
NSString *newTheme = ([sender tag] == 0) ? @"default" : @"dark";
[SPTracker trackSettingsThemeUpdated:newTheme];
[[VSThemeManager sharedManager] swapTheme:newTheme];
}

[self updateThemeMenuForPosition:[sender tag]];
}

Expand Down

0 comments on commit d80658e

Please sign in to comment.