Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="KYAGeneralSettingsViewController">
<connections>
<outlet property="hideMenuBarIconCheckBoxButton" destination="hide-icon-btn" id="hide-icon-outlet"/>
<outlet property="notificationSettingsButton" destination="OlQ-t6-SFN" id="aV4-Uq-iP7"/>
<outlet property="startAtLoginCheckBoxButton" destination="b2B-0v-BKX" id="XmM-6C-DT2"/>
<outlet property="view" destination="nJr-ua-jG7" id="MTl-QF-Qea"/>
Expand All @@ -32,6 +33,26 @@
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="hide-icon-btn">
<rect key="frame" x="-2" y="21" width="120" height="18"/>
<buttonCell key="cell" type="check" title="Hide Menu Bar Icon" bezelStyle="regularSquare" imagePosition="left" state="off" inset="2" id="hide-icon-cell">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent">h</string>
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</buttonCell>
<connections>
<binding destination="CIJ-dN-fzc" name="value" keyPath="values.info.marcel-dierkes.KeepingYouAwake.MenuBarIconHidden" id="hide-icon-binding"/>
</connections>
</button>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hide-icon-help">
<rect key="frame" x="-2" y="0.0" width="289" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Hides the app's icon from the menu bar." id="hide-icon-help-cell">
<font key="font" metaFont="message" size="11"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fqh-NM-7oy">
<rect key="frame" x="-2" y="0.0" width="289" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Automatically opens the app when you start your Mac." id="jxf-J8-dHN">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@interface KYAGeneralSettingsViewController ()
@property (weak, nonatomic) IBOutlet NSButton *startAtLoginCheckBoxButton;
@property (weak, nonatomic) IBOutlet NSButton *notificationSettingsButton;
@property (weak, nonatomic) IBOutlet NSButton *hideMenuBarIconCheckBoxButton;
@property (weak, nonatomic) KYAStatusItemController *statusItemController;
@end

@implementation KYAGeneralSettingsViewController
Expand Down Expand Up @@ -39,7 +41,7 @@ + (NSString *)preferredTitle
- (void)viewDidLoad
{
[super viewDidLoad];

// Bind the start at login checkbox value to NSApplication
[self.startAtLoginCheckBoxButton bind:@"value"
toObject:NSApplication.sharedApplication
Expand All @@ -49,16 +51,45 @@ - (void)viewDidLoad
NSConditionallySetsEnabledBindingOption: @YES
}
];


// Set initial state from user defaults
self.hideMenuBarIconCheckBoxButton.state = [NSUserDefaults standardUserDefaults].kya_isMenuBarIconHidden;

// Observe changes to update status item visibility
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(userDefaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:NSUserDefaults.standardUserDefaults];

if(@available(macOS 11.0, *)) {} else
{
self.notificationSettingsButton.hidden = YES;
}

// Get reference to app controller for status item access
NSApplication *app = NSApplication.sharedApplication;
id<NSApplicationDelegate> delegate = app.delegate;
if([delegate isKindOfClass:NSClassFromString(@"KYAAppDelegate")])
{
id appController = [delegate valueForKey:@"appController"];
if([appController isKindOfClass:NSClassFromString(@"KYAAppController")])
{
self.statusItemController = [appController valueForKey:@"statusItemController"];
}
}
}

- (void)dealloc
{
[self.startAtLoginCheckBoxButton unbind:@"value"];
[NSNotificationCenter.defaultCenter removeObserver:self];
}

- (void)userDefaultsDidChange:(NSNotification *)notification
{
BOOL isHidden = [NSUserDefaults standardUserDefaults].kya_isMenuBarIconHidden;
self.statusItemController.systemStatusItem.visible = !isHidden;
}
}

- (void)openNotificationSettings:(id)sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ @implementation NSUserDefaults (KYAKeys)

#pragma mark - Battery Capacity Threshold

KYA_GENERATE_BOOL_PROPERTY(isMenuBarIconHidden,
menuBarIconHidden,
MenuBarIconHidden);

NSString * const KYAUserDefaultsKeyBatteryCapacityThreshold = @"info.marcel-dierkes.KeepingYouAwake.BatteryCapacityThreshold";

- (CGFloat)kya_batteryCapacityThreshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ KYA_EXPORT NSString * const KYAUserDefaultsKeyBatteryCapacityThresholdEnabled;
KYA_EXPORT NSString * const KYAUserDefaultsKeyBatteryCapacityThreshold;
KYA_EXPORT NSString * const KYAUserDefaultsKeyLowPowerModeMonitoringEnabled;
KYA_EXPORT NSString * const KYAUserDefaultsKeyPreReleaseUpdatesEnabled;
KYA_EXPORT NSString * const KYAUserDefaultsKeyMenuBarIconHidden;

@interface NSUserDefaults (KYAKeys)

Expand Down Expand Up @@ -58,6 +59,9 @@ KYA_EXPORT NSString * const KYAUserDefaultsKeyPreReleaseUpdatesEnabled;
/// Returns YES if the app should deactivate when the user account is switched.
@property (nonatomic, getter=kya_isDeactivateOnUserSwitchEnabled) BOOL kya_deactivateOnUserSwitchEnabled;

/// Returns YES if the menu bar icon should be hidden.
@property (nonatomic, getter=kya_isMenuBarIconHidden) BOOL kya_menuBarIconHidden;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ - (void)configureStatusItem
{
Auto statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
statusItem.highlightMode = ![NSUserDefaults standardUserDefaults].kya_menuBarIconHighlightDisabled;
statusItem.visible = ![NSUserDefaults standardUserDefaults].kya_menuBarIconHidden;
if([statusItem respondsToSelector:@selector(behavior)])
{
statusItem.behavior = NSStatusItemBehaviorTerminationOnRemoval;
Expand All @@ -41,13 +42,13 @@ - (void)configureStatusItem
{
statusItem.visible = YES;
}

Auto button = statusItem.button;

[button sendActionOn:NSEventMaskLeftMouseUp|NSEventMaskRightMouseUp];
button.target = self;
button.action = @selector(toggleStatus:);

#if DEBUG
if(@available(macOS 10.14, *))
{
Expand All @@ -56,7 +57,7 @@ - (void)configureStatusItem
Auto log = KYALogCreateWithCategory("StatusItemUI");
os_log_debug(log, "Blue status bar item color is enabled for DEBUG builds.");
#endif

self.systemStatusItem = statusItem;
self.appearance = KYAStatusItemAppearanceInactive;
}
Expand All @@ -65,15 +66,15 @@ - (void)toggleStatus:(id)sender
{
Auto delegate = self.delegate;
Auto event = NSApplication.sharedApplication.currentEvent;

if((event.modifierFlags & NSEventModifierFlagControl) // ctrl click
|| (event.modifierFlags & NSEventModifierFlagOption) // alt click
|| (event.type == NSEventTypeRightMouseUp)) // right click
{
[self showMenuFromDataSource];
return;
}

if([delegate respondsToSelector:@selector(statusItemControllerShouldPerformPrimaryAction:)])
{
[delegate statusItemControllerShouldPerformPrimaryAction:self];
Expand All @@ -91,10 +92,10 @@ - (KYAStatusItemAppearance)appearance
- (void)setAppearance:(KYAStatusItemAppearance)appearance
{
[self willChangeValueForKey:@"appearance"];

Auto button = self.systemStatusItem.button;
Auto imageProvider = KYAStatusItemImageProvider.currentProvider;

if(appearance == KYAStatusItemAppearanceActive)
{
button.image = imageProvider.activeIconImage;
Expand All @@ -105,7 +106,7 @@ - (void)setAppearance:(KYAStatusItemAppearance)appearance
button.image = imageProvider.inactiveIconImage;
button.toolTip = KYA_L10N_CLICK_TO_PREVENT_SLEEP;
}

[self didChangeValueForKey:@"appearance"];
}

Expand Down