From 44198714f1e788009b9afe7422667a2516b7eae5 Mon Sep 17 00:00:00 2001 From: DaFuqtor <46137336+DaFuqtor@users.noreply.github.com> Date: Thu, 8 Aug 2019 12:28:04 +0300 Subject: [PATCH] Show/Hide Status Bar Icon - Defaults for showing/hiding status bar icon - Quit the app when status bar item is opened using default key equivalent (command+Q) - Changed homepage ("About" button) - Added app category: Productivity --- Controller.m | 4 ++-- Info.plist | 6 ++++-- README.md | 6 ++++++ TrayMenu.m | 47 ++++++++++++++++++++++++----------------------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Controller.m b/Controller.m index e1a8ffc..b88c01b 100644 --- a/Controller.m +++ b/Controller.m @@ -68,7 +68,7 @@ - (void)start wasThreeDown = NO; needToClick = - [[NSUserDefaults standardUserDefaults] boolForKey:@"need_to_click"]; + [[NSUserDefaults standardUserDefaults] boolForKey:@"needClick"]; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; [NSApplication sharedApplication]; @@ -172,7 +172,7 @@ - (BOOL)getClickMode - (void)setMode:(BOOL)click { - [[NSUserDefaults standardUserDefaults] setBool:click forKey:@"need_to_click"]; + [[NSUserDefaults standardUserDefaults] setBool:click forKey:@"needClick"]; needToClick = click; } diff --git a/Info.plist b/Info.plist index 6b763ab..ea22805 100755 --- a/Info.plist +++ b/Info.plist @@ -15,11 +15,13 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.3 + 2.4 CFBundleSignature ???? CFBundleVersion - 11042019 + 08082019 + LSApplicationCategoryType + public.app-category.productivity LSBackgroundOnly NSHighResolutionCapable diff --git a/README.md b/README.md index 4ea4b54..c001a08 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,12 @@ After installation, I recommend to osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/MiddleClick.app", hidden:true}' ``` +### Show/Hide Status Bar Icon + +```bash +defaults write com.rouge41.middleClick hideMenuBarItem true # default is false +``` + --- #### If you can’t even imagine why you need this: diff --git a/TrayMenu.m b/TrayMenu.m index 353adb2..d32b80e 100644 --- a/TrayMenu.m +++ b/TrayMenu.m @@ -22,7 +22,7 @@ - (id)initWithController:(Controller*)ctrl - (void)openWebsite:(id)sender { NSURL* url = [NSURL - URLWithString:@"http://clement.beffa.org/labs/projects/middleclick/"]; + URLWithString:@"https://github.com/DaFuqtor/MiddleClick"]; [[NSWorkspace sharedWorkspace] openURL:url]; } @@ -87,7 +87,7 @@ - (NSMenu*)createMenu // Add Quit Action menuItem = [menu addItemWithTitle:@"Quit" action:@selector(actionQuit:) - keyEquivalent:@""]; + keyEquivalent:@"q"]; [menuItem setTarget:self]; @@ -96,28 +96,29 @@ - (NSMenu*)createMenu - (void)applicationDidFinishLaunching:(NSNotification*)notification { - NSMenu* menu = [self createMenu]; - - // Check if Darkmode menubar is supported and enable templating of the icon in - // that case. - - NSImage* icon = [NSApp applicationIconImage]; - [icon setSize:CGSizeMake(19, 19)]; - - BOOL oldBusted = (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9); - if (!oldBusted) { - // 10.10 or higher, so setTemplate: is safe - [icon setTemplate:YES]; + if (![[NSUserDefaults standardUserDefaults] boolForKey:@"hideMenuBarItem"]) { + NSMenu* menu = [self createMenu]; + + // Check if Darkmode menubar is supported and enable templating of the icon in + // that case. + + NSImage* icon = [NSApp applicationIconImage]; + [icon setSize:CGSizeMake(19, 19)]; + + BOOL oldBusted = (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9); + if (!oldBusted) { + // 10.10 or higher, so setTemplate: is safe + [icon setTemplate:YES]; + } + + _statusItem = [[[NSStatusBar systemStatusBar] + statusItemWithLength:NSSquareStatusItemLength] retain]; + _statusItem.menu = menu; + _statusItem.button.toolTip = @"MiddleClick"; + _statusItem.button.image = icon; + + [menu release]; } - - _statusItem = [[[NSStatusBar systemStatusBar] - statusItemWithLength:NSSquareStatusItemLength] retain]; - _statusItem.highlightMode = YES; - _statusItem.menu = menu; - _statusItem.button.toolTip = @"MiddleClick"; - _statusItem.button.image = icon; - - [menu release]; } @end