diff --git a/Mute Me Now/AppDelegate.h b/Mute Me Now/AppDelegate.h index 73d4465..cda7a15 100644 --- a/Mute Me Now/AppDelegate.h +++ b/Mute Me Now/AppDelegate.h @@ -14,6 +14,7 @@ - (IBAction)menuMenuItemAction:(id)sender; - (void) hideMenuBar:(BOOL)enableState; +- (void) updateMenuItemIcon; - (void) shortCutKeyPressed; diff --git a/Mute Me Now/AppDelegate.m b/Mute Me Now/AppDelegate.m index a057256..169f92f 100644 --- a/Mute Me Now/AppDelegate.m +++ b/Mute Me Now/AppDelegate.m @@ -25,28 +25,61 @@ @implementation AppDelegate NSString *STATUS_ICON_RED = @"tray-active"; NSString *STATUS_ICON_WHITE = @"tray-unactive-white"; +NSString *STATUS_ICON_OFF = @"micOff"; +NSString *STATUS_ICON_ON = @"micOn"; + - (void) awakeFromNib { BOOL hideStatusBar = NO; + BOOL statusBarButtonToggle = NO; + BOOL useAlternateStatusBarIcons = NO; if ([[NSUserDefaults standardUserDefaults] objectForKey:@"hide_status_bar"] != nil) { hideStatusBar = [[NSUserDefaults standardUserDefaults] boolForKey:@"hide_status_bar"]; } - if (!hideStatusBar) { - [self setupStatusBarItem]; + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"status_bar_button_toggle"] != nil) { + statusBarButtonToggle = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_button_toggle"]; + } + + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"status_bar_alternate_icons"] != nil) { + useAlternateStatusBarIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_alternate_icons"]; } [[NSUserDefaults standardUserDefaults] setBool:hideStatusBar forKey:@"hide_status_bar"]; + [[NSUserDefaults standardUserDefaults] setBool:statusBarButtonToggle forKey:@"status_bar_button_toggle"]; + [[NSUserDefaults standardUserDefaults] setBool:useAlternateStatusBarIcons forKey:@"status_bar_alternate_icons"]; + + if (!hideStatusBar) { + [self setupStatusBarItem]; + } // masshortcut [self setShortcutKey]; } - (void) setupStatusBarItem { - - self.statusBar = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; + BOOL statusBarButtonToggle = NO; + + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"status_bar_button_toggle"] != nil) { + statusBarButtonToggle = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_button_toggle"]; + } + + if (statusBarButtonToggle) { + NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; + NSStatusBarButton *statusButton = statusItem.button; + + statusButton.target = self; + statusButton.action = @selector(handleStatusButtonAction); + + [statusButton sendActionOn:NSEventMaskLeftMouseUp|NSEventMaskRightMouseUp]; + + self.statusBar = statusItem; + } else { + self.statusBar = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; + self.statusBar.menu = self.statusMenu; + } NSImage* statusImage = [self getStatusBarImage]; @@ -55,12 +88,11 @@ - (void) setupStatusBarItem { // allows cocoa to change the background of the icon [statusImage setTemplate:YES]; - self.statusBar = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; self.statusBar.image = statusImage; self.statusBar.highlightMode = YES; self.statusBar.enabled = YES; - self.statusBar.menu = self.statusMenu; - + + [self updateMenuItemIcon]; } - (void) setShortcutKey { @@ -98,6 +130,12 @@ - (void) shortCutKeyPressed { } +- (void) showMenu { + + [self.statusBar popUpStatusItemMenu:self.statusMenu]; + +} + - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[[[NSApplication sharedApplication] windows] lastObject] close]; @@ -144,16 +182,28 @@ -(void)darkModeChanged:(NSNotification *)notif - (NSImage*) getStatusBarImage { - NSImage* statusImage = [NSImage imageNamed:STATUS_ICON_BLACK]; - - // see https://stackoverflow.com/questions/25379525/how-to-detect-dark-mode-in-yosemite-to-change-the-status-bar-menu-icon - NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain]; - id style = [dict objectForKey:@"AppleInterfaceStyle"]; - - BOOL darkModeOn = ( style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"] ); - - if (darkModeOn) { - statusImage = [NSImage imageNamed:STATUS_ICON_WHITE]; + BOOL useAlternateIcons = NO; + + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"status_bar_alternate_icons"] != nil) { + useAlternateIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_alternate_icons"]; + } + + NSImage* statusImage; + + if (useAlternateIcons) { + statusImage = [NSImage imageNamed:STATUS_ICON_ON]; + } else { + statusImage = [NSImage imageNamed:STATUS_ICON_BLACK]; + + // see https://stackoverflow.com/questions/25379525/how-to-detect-dark-mode-in-yosemite-to-change-the-status-bar-menu-icon + NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain]; + id style = [dict objectForKey:@"AppleInterfaceStyle"]; + + BOOL darkModeOn = ( style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"] ); + + if (darkModeOn) { + statusImage = [NSImage imageNamed:STATUS_ICON_WHITE]; + } } return statusImage; @@ -166,13 +216,27 @@ - (void) setStatusBarImgRed:(BOOL) shouldBeRed { if (shouldBeRed) { NSLog (@"using red"); - statusImage = [NSImage imageNamed:STATUS_ICON_RED]; + + BOOL useAlternateIcons = NO; + + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"status_bar_alternate_icons"] != nil) { + useAlternateIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_alternate_icons"]; + } + + if (useAlternateIcons) { + statusImage = [NSImage imageNamed:STATUS_ICON_OFF]; + [statusImage setTemplate:YES]; + } else { + statusImage = [NSImage imageNamed:STATUS_ICON_RED]; + [statusImage setTemplate:!shouldBeRed]; + } + } statusImage.size = NSMakeSize(18, 18); - [statusImage setTemplate:!shouldBeRed]; - + self.statusBar.image = statusImage; + } @@ -279,6 +343,14 @@ - (IBAction)menuMenuItemAction:(id)sender { [self updateMenuItem]; } +- (void) updateMenuItemIcon { + if (self.muteMenuItem.state == NSOnState) { + [self setStatusBarImgRed:YES]; + } else { + [self setStatusBarImgRed:NO]; + } +} + - (void) updateMenuItem { if (self.muteMenuItem.state == NSOffState) { @@ -296,6 +368,18 @@ - (void) updateMenuItem { } +- (void) handleStatusButtonAction { + NSEvent *event = [[NSApplication sharedApplication] currentEvent]; + + if ((event.modifierFlags & NSEventModifierFlagControl) || (event.modifierFlags & NSEventModifierFlagOption) || (event.type == NSEventTypeRightMouseUp)) { + + [self showMenu]; + + return; + } + + [self updateMenuItem]; +} @end diff --git a/Mute Me Now/Assets.xcassets/micOff.imageset/Contents.json b/Mute Me Now/Assets.xcassets/micOff.imageset/Contents.json new file mode 100644 index 0000000..1f7b4e3 --- /dev/null +++ b/Mute Me Now/Assets.xcassets/micOff.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "ios7-mic-off.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "ios7-mic-off-1.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "ios7-mic-off-2.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off-1.png b/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off-1.png new file mode 100644 index 0000000..07685a6 Binary files /dev/null and b/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off-1.png differ diff --git a/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off-2.png b/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off-2.png new file mode 100644 index 0000000..07685a6 Binary files /dev/null and b/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off-2.png differ diff --git a/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off.png b/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off.png new file mode 100644 index 0000000..07685a6 Binary files /dev/null and b/Mute Me Now/Assets.xcassets/micOff.imageset/ios7-mic-off.png differ diff --git a/Mute Me Now/Assets.xcassets/micOn.imageset/Contents.json b/Mute Me Now/Assets.xcassets/micOn.imageset/Contents.json new file mode 100644 index 0000000..a312bba --- /dev/null +++ b/Mute Me Now/Assets.xcassets/micOn.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "ios7-mic.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "ios7-mic-1.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "ios7-mic-2.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic-1.png b/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic-1.png new file mode 100644 index 0000000..7870823 Binary files /dev/null and b/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic-1.png differ diff --git a/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic-2.png b/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic-2.png new file mode 100644 index 0000000..7870823 Binary files /dev/null and b/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic-2.png differ diff --git a/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic.png b/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic.png new file mode 100644 index 0000000..7870823 Binary files /dev/null and b/Mute Me Now/Assets.xcassets/micOn.imageset/ios7-mic.png differ diff --git a/Mute Me Now/Base.lproj/Main.storyboard b/Mute Me Now/Base.lproj/Main.storyboard index a3772b6..2e63df9 100644 --- a/Mute Me Now/Base.lproj/Main.storyboard +++ b/Mute Me Now/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -666,20 +666,20 @@ - + - + - - + + - + - - + + @@ -698,6 +698,9 @@ + + + @@ -712,27 +715,26 @@ - + - - - - - - + + + - - + + + - - + + + @@ -740,7 +742,7 @@ - - + + - - + + - - - - + + + + + - + - - - - - - + + + - - - + - - + - - - - - - - + + + + + - + - + + @@ -865,12 +884,14 @@ + + - + diff --git a/Mute Me Now/Mute Me Now Launcher/Mute Me Now Launcher/ViewController.m b/Mute Me Now/Mute Me Now Launcher/Mute Me Now Launcher/ViewController.m index 61c8e8c..4f60c53 100644 --- a/Mute Me Now/Mute Me Now Launcher/Mute Me Now Launcher/ViewController.m +++ b/Mute Me Now/Mute Me Now Launcher/Mute Me Now Launcher/ViewController.m @@ -17,4 +17,7 @@ - (void)setRepresentedObject:(id)representedObject { - (IBAction)showMenuBarChanged:(id)sender { } + +- (IBAction)statusBarToggleChanged:(id)sender { +} @end diff --git a/Mute Me Now/ViewController.h b/Mute Me Now/ViewController.h index 2055d0f..ba62084 100644 --- a/Mute Me Now/ViewController.h +++ b/Mute Me Now/ViewController.h @@ -7,10 +7,14 @@ @property (weak) IBOutlet NSButton *websiteButton; @property (weak) IBOutlet NSButton *autoLoginState; @property (weak) IBOutlet NSButton *showInMenuBarState; +@property (weak) IBOutlet NSButton *statusBarButtonToggle; +@property (weak) IBOutlet NSButton *useAlternateStatusBarIcons; @property (strong) IBOutlet MASShortcutView *masShortCutView; - (IBAction)showMenuBarChanged:(id)sender; +- (IBAction)statusBarToggleChanged:(id)sender; +- (IBAction)useAlternateStatusBarIconsChanged:(id)sender; @end diff --git a/Mute Me Now/ViewController.m b/Mute Me Now/ViewController.m index 74c5c1b..b786ad6 100644 --- a/Mute Me Now/ViewController.m +++ b/Mute Me Now/ViewController.m @@ -25,9 +25,14 @@ - (void)viewDidLoad { BOOL state = [[NSUserDefaults standardUserDefaults] boolForKey:@"auto_login"]; [self.autoLoginState setState: !state]; - BOOL hideStatusBarState = [[NSUserDefaults standardUserDefaults] boolForKey:@"hide_status_bar"]; [self.showInMenuBarState setState: hideStatusBarState]; + + BOOL statusBarButtonToggle = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_button_toggle"]; + [self.statusBarButtonToggle setState: statusBarButtonToggle]; + + BOOL useAlternateStatusBarIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_alternate_icons"]; + [self.useAlternateStatusBarIcons setState: useAlternateStatusBarIcons]; // enable to nil out preferences @@ -128,6 +133,7 @@ - (IBAction)showMenuBarChanged:(id)sender { if (enableState == YES) { + //self.statusBarButtonToggle NSString *msgText = @"Long press on the Touch Bar Mute Button to show Preferences when the Menu Item is disabled."; @@ -141,7 +147,51 @@ - (IBAction)showMenuBarChanged:(id)sender { } +- (IBAction)statusBarToggleChanged:(id)sender { + + NSInteger hideState = [self.showInMenuBarState state]; + + if(hideState == NSOnState) { + return; + } + + NSInteger state = [self.statusBarButtonToggle state]; + + BOOL enableState = NO; + if(state == NSOnState) { + enableState = YES; + } + + [[NSUserDefaults standardUserDefaults] setBool:enableState forKey:@"status_bar_button_toggle"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate]; + [appDelegate hideMenuBar:NO]; + +} +- (IBAction)useAlternateStatusBarIconsChanged:(id)sender { + + NSInteger hideState = [self.showInMenuBarState state]; + + if(hideState == NSOnState) { + return; + } + + NSInteger state = [self.useAlternateStatusBarIcons state]; + + BOOL enableState = NO; + if(state == NSOnState) { + enableState = YES; + } + + [[NSUserDefaults standardUserDefaults] setBool:enableState forKey:@"status_bar_alternate_icons"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate]; + [appDelegate hideMenuBar:NO]; + +} - (IBAction)onMainWebsitePressed:(id)sender { diff --git a/README.md b/README.md index 6628ff8..2effe1d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ When you’re in a meeting using Hangouts, Skype, Slack, or another voice applic - find the Open at Login option in Preferences - add custom shortcut for Mute/Unmute (default cmd + shift + 0) in Preferences - show/hide Mute/Unmute button in MacOS menu bar in Preferences +- configure functionality to Mute/Unmute by left clicking icon in MacOS menu bar (right click to open menu) in Preferences +- configure alternate set of icons for MacOS menu bar (for those that prefer monochromatic icons) in Preferences ### Ideas for development If you have any ideas that can help us improve this application, please create a new issue.