Skip to content

Commit

Permalink
Merge pull request #272 from Tatsh/bc-fix
Browse files Browse the repository at this point in the history
Add support to build on 10.15 and lower version SDKs
  • Loading branch information
yujitach authored Nov 17, 2021
2 parents 9107aa9 + 9546671 commit 5c959eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
31 changes: 20 additions & 11 deletions MenuMetersMenuExtraBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,20 @@ - (void)configDisplay:(NSString*)bundleID fromPrefs:(MenuMeterDefaults*)ourPrefs
if([ourPrefs loadBoolPref:bundleID defaultValue:YES]){
if(!statusItem){
statusItem=[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600)
if(@available(macOS 11,*)){
// 11.0.1 does not keep the position unless autosaveName is explicitly set,
// see https://github.com/feedback-assistant/reports/issues/151 .
// This is done here in order not to lose positions on pre-macOS 11 systems.
statusItem.autosaveName=self.bundleID;
}
#endif
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101200)
if(@available(macOS 10.12,*)){
statusItem.behavior=NSStatusItemBehaviorRemovalAllowed;
[statusItem addObserver:self forKeyPath:@"visible" options:NSKeyValueObservingOptionNew context:nil];
}
#endif
statusItem.menu = self.menu;
statusItem.menu.delegate = self;
/*
Expand Down Expand Up @@ -222,27 +226,30 @@ - (void)addStandardMenuEntriesTo:(NSMenu*)extraMenu
}
-(BOOL)isDark
{
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101400)
if(@available(macOS 10.14,*)){
// https://github.com/ruiaureliano/macOS-Appearance/blob/master/Appearance/Source/AppDelegate.swift
return [statusItem.button.effectiveAppearance.name containsString:@"ark"];
}else{
// https://stackoverflow.com/questions/25207077/how-to-detect-if-os-x-is-in-dark-mode
// On 10.10 there is no documented API for theme, so we'll guess a couple of different ways.
BOOL isDark = NO;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults synchronize];
NSString *interfaceStyle = [defaults stringForKey:@"AppleInterfaceStyle"];
if (interfaceStyle && [interfaceStyle isEqualToString:@"Dark"]) {
isDark = YES;
}
return isDark;
}
#endif
// https://stackoverflow.com/questions/25207077/how-to-detect-if-os-x-is-in-dark-mode
// On 10.10 there is no documented API for theme, so we'll guess a couple of different ways.
BOOL isDark = NO;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults synchronize];
NSString *interfaceStyle = [defaults stringForKey:@"AppleInterfaceStyle"];
if (interfaceStyle && [interfaceStyle isEqualToString:@"Dark"]) {
isDark = YES;
}
return isDark;
}
-(NSColor*)menuBarTextColor
{
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101400)
if(@available(macOS 10.14,*)){
return [NSColor labelColor];
}
#endif
if (self.isDark){
return [NSColor whiteColor];
}
Expand All @@ -258,9 +265,11 @@ -(CGFloat)height
return height;
}
- (void)setupAppearance {
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101400)
if(@available(macOS 10.14,*)){
[NSAppearance setCurrentAppearance:statusItem.button.effectiveAppearance];
}
#endif
}
#pragma mark NSMenuDelegate
- (void)menuNeedsUpdate:(NSMenu*)menu {
Expand Down
4 changes: 4 additions & 0 deletions PrefPane/MenuMetersPref.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ -(void)initCommon:(NSString*)about
}
[self setupSparkleUI];

#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600)
if (@available(macOS 10.16, *)) {
NSToolbar *toolbar = [NSToolbar new];
toolbar.delegate = self;
Expand All @@ -177,6 +178,7 @@ -(void)initCommon:(NSString*)about
[self.window.toolbar setSelectedItemIdentifier:selectedIdentifier];
prefTabs.delegate = self;
}
#endif
}

- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
Expand All @@ -203,9 +205,11 @@ - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString
item.paletteLabel = tabItem.label;
item.label = tabItem.label;
item.action = @selector(toolbarSelection:);
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600)
if (@available(macOS 10.16, *)) {
item.image = [NSImage imageWithSystemSymbolName:itemIdent accessibilityDescription:@""];
}
#endif
return item;
}

Expand Down

0 comments on commit 5c959eb

Please sign in to comment.