Skip to content

Commit

Permalink
allow hiding the menu bar item
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Feb 12, 2015
1 parent b477213 commit 50e3a0f
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 25 deletions.
36 changes: 35 additions & 1 deletion FlashlightApp/EasySIMBL/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ @interface AppDelegate ()
@property (nonatomic,weak) IBOutlet NSMenuItem *createNewAutomatorPluginMenuItem;
@property (nonatomic,weak) IBOutlet NSTextField *versionLabel, *searchAnything;
@property (nonatomic,weak) IBOutlet NSButton *openGithub, *requestPlugin, *leaveFeedback;
@property (nonatomic,weak) IBOutlet NSWindow *aboutWindow;
@property (nonatomic,weak) IBOutlet NSButton *menuBarItemPreferenceButton;

@end

Expand Down Expand Up @@ -47,7 +49,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification

[self checkSpotlightVersion];

[self setupURLHandling];
[self setupDefaults];

self.versionLabel.stringValue = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];

Expand Down Expand Up @@ -116,8 +118,13 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
self.openGithub.stringValue = NSLocalizedString(@"Contribute on GitHub", @"");
self.requestPlugin.stringValue = NSLocalizedString(@"Request a Plugin", @"");
self.searchAnything.stringValue = NSLocalizedString(@"Search anything.", @"");
self.menuBarItemPreferenceButton.stringValue = NSLocalizedString(@"Show menu bar item", @"");
[self.menuBarItemPreferenceButton sizeToFit];
self.menuBarItemPreferenceButton.frame = NSMakeRect(self.menuBarItemPreferenceButton.superview.bounds.size.width/2 - self.menuBarItemPreferenceButton.frame.size.width/2, self.menuBarItemPreferenceButton.frame.origin.y, self.menuBarItemPreferenceButton.frame.size.width, self.menuBarItemPreferenceButton.frame.size.height);

[UpdateChecker shared]; // begin fetch

[self setupURLHandling];
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
Expand Down Expand Up @@ -300,7 +307,34 @@ - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEv
[self.pluginListController showCategory:parts[1]];
} else if (parts.count == 1 && [parts[0] isEqualToString:@"search"]) {
[self.pluginListController showSearch:query[@"q"]];
} else if (parts.count >= 1 && [parts[0] isEqualToString:@"preferences"]) {
if (parts.count == 2 && [parts[1] isEqualToString:@"menuBarItem"]) {
[self.aboutWindow makeKeyAndOrderFront:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// in case we're mid-launch — we don't want the main window to be made key above this window
[self.aboutWindow makeKeyAndOrderFront:nil];
});
}
}
}
}
#pragma mark Preferences
- (void)setupDefaults {
NSDictionary *defaults = @{
@"ShowMenuItem": @YES
};
for (NSString *key in defaults) {
if (![[NSUserDefaults standardUserDefaults] valueForKey:key]) {
[[NSUserDefaults standardUserDefaults] setValue:defaults[key] forKey:key];
}
}
}

- (IBAction)showMenuBarItemPressed:(id)sender {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.nateparrott.Flashlight.DefaultsChanged" object:@"com.nateparrott.Flashlight" userInfo:nil options:NSNotificationPostToAllSessions | NSNotificationDeliverImmediately];
});
}

@end
36 changes: 25 additions & 11 deletions FlashlightApp/EasySIMBL/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@
</menu>
<customObject id="494" customClass="AppDelegate">
<connections>
<outlet property="aboutWindow" destination="Nbs-13-Twb" id="JQi-Kg-U2G"/>
<outlet property="leaveFeedback" destination="YyB-xf-RjT" id="MGc-ch-NJm"/>
<outlet property="menuBarItemPreferenceButton" destination="Llk-bz-SPb" id="grz-AH-VkL"/>
<outlet property="openGithub" destination="no0-HV-O9k" id="12n-tY-kFy"/>
<outlet property="pluginListController" destination="715" id="OyI-Qw-pUc"/>
<outlet property="requestPlugin" destination="QeJ-hd-3A1" id="AK4-6B-Nzq"/>
Expand Down Expand Up @@ -591,23 +593,23 @@
<point key="canvasLocation" x="202.5" y="588"/>
</customView>
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="Nbs-13-Twb" userLabel="About">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="109" y="138" width="242" height="333"/>
<rect key="contentRect" x="109" y="138" width="242" height="361"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="800"/>
<value key="minSize" type="size" width="242" height="260"/>
<value key="maxSize" type="size" width="242" height="260"/>
<view key="contentView" id="ML2-hK-xgc">
<rect key="frame" x="0.0" y="-1" width="242" height="333"/>
<rect key="frame" x="0.0" y="-5" width="242" height="361"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="bs8-1N-RgN">
<rect key="frame" x="75" y="221" width="92" height="92"/>
<rect key="frame" x="75" y="249" width="92" height="92"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="Icon" id="QLY-QW-30e"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="b4m-8B-Vhn">
<rect key="frame" x="18" y="161" width="206" height="30"/>
<rect key="frame" x="18" y="189" width="206" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Flashlight" id="CKY-mr-H4g">
<font key="font" size="25" name="HelveticaNeue-Light"/>
Expand All @@ -616,7 +618,7 @@
</textFieldCell>
</textField>
<button id="no0-HV-O9k">
<rect key="frame" x="38" y="82" width="166" height="29"/>
<rect key="frame" x="38" y="110" width="166" height="29"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Contribute on GitHub" bezelStyle="regularSquare" alignment="center" borderStyle="border" inset="2" id="P0e-Mj-nLE">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -627,7 +629,7 @@
</connections>
</button>
<button id="YyB-xf-RjT">
<rect key="frame" x="38" y="50" width="166" height="29"/>
<rect key="frame" x="38" y="78" width="166" height="29"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Leave Feedback" bezelStyle="regularSquare" alignment="center" borderStyle="border" inset="2" id="NO4-GD-LyW">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -638,7 +640,7 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="gNj-56-AoU">
<rect key="frame" x="18" y="123" width="206" height="17"/>
<rect key="frame" x="18" y="151" width="206" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Search anything." id="Zut-6I-UVj">
<font key="font" metaFont="system"/>
Expand All @@ -647,7 +649,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="v99-pH-dRh">
<rect key="frame" x="18" y="145" width="206" height="11"/>
<rect key="frame" x="18" y="173" width="206" height="11"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Version ?.??" id="kFB-vx-lDm">
<font key="font" metaFont="miniSystem"/>
Expand All @@ -656,7 +658,7 @@
</textFieldCell>
</textField>
<button id="QeJ-hd-3A1">
<rect key="frame" x="38" y="17" width="166" height="29"/>
<rect key="frame" x="38" y="45" width="166" height="29"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Request a Plugin" bezelStyle="regularSquare" alignment="center" borderStyle="border" inset="2" id="b4y-N1-H7G">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -666,9 +668,21 @@
<action selector="requestAPlugin:" target="494" id="zBI-z8-sAl"/>
</connections>
</button>
<button id="Llk-bz-SPb">
<rect key="frame" x="38" y="18" width="166" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="check" title="Show menu bar icon" bezelStyle="regularSquare" imagePosition="left" alignment="center" state="on" inset="2" id="AtZ-Rw-Wyh">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="showMenuBarItemPressed:" target="494" id="ykO-0C-Nv9"/>
<binding destination="702" name="value" keyPath="values.ShowMenuItem" id="PE1-lx-tPa"/>
</connections>
</button>
</subviews>
</view>
<point key="canvasLocation" x="-242" y="521.5"/>
<point key="canvasLocation" x="-242" y="535.5"/>
</window>
<scrollView autohidesScrollers="YES" horizontalLineScroll="96" horizontalPageScroll="10" verticalLineScroll="96" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="IJ7-m0-7jG" userLabel="Plugin List">
<rect key="frame" x="0.0" y="0.0" width="454" height="448"/>
Expand Down
4 changes: 2 additions & 2 deletions FlashlightApp/EasySIMBL/Flashlight-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.97.0</string>
<string>0.97.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -65,7 +65,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>41</string>
<string>42</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
49 changes: 47 additions & 2 deletions FlashlightApp/SIMBL Agent/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -1163,12 +1163,30 @@
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
<string key="NSAction">submenuAction:</string>
<reference key="NSTarget"/>
<reference key="NSTarget" ref="701433788"/>
<object class="NSMenu" key="NSSubmenu" id="701433788">
<string key="NSTitle"/>
<array class="NSMutableArray" key="NSMenuItems"/>
</object>
</object>
<object class="NSMenuItem" id="191023024">
<reference key="NSMenu" ref="1043790343"/>
<bool key="NSIsDisabled">YES</bool>
<bool key="NSIsSeparator">YES</bool>
<string key="NSTitle"/>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="1004967477">
<reference key="NSMenu" ref="1043790343"/>
<string key="NSTitle">Hide this menu...</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
</array>
</object>
</array>
Expand Down Expand Up @@ -1702,6 +1720,14 @@
</object>
<int key="connectionID">475</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">hideThisMenu:</string>
<reference key="source" ref="319322392"/>
<reference key="destination" ref="1004967477"/>
</object>
<int key="connectionID">480</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
Expand Down Expand Up @@ -2568,6 +2594,8 @@
<reference ref="847989738"/>
<reference ref="706656518"/>
<reference ref="412134391"/>
<reference ref="1004967477"/>
<reference ref="191023024"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand Down Expand Up @@ -2610,6 +2638,16 @@
<array class="NSMutableArray" key="children"/>
<reference key="parent" ref="412134391"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">478</int>
<reference key="object" ref="1004967477"/>
<reference key="parent" ref="1043790343"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">479</int>
<reference key="object" ref="191023024"/>
<reference key="parent" ref="1043790343"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand Down Expand Up @@ -2732,6 +2770,8 @@
<string key="463.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="468.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="471.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="478.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="479.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="57.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
Expand All @@ -2753,7 +2793,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">477</int>
<int key="maxID">480</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -2777,13 +2817,18 @@
<string key="className">UIManager</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="getNewPlugins:">id</string>
<string key="hideThisMenu:">id</string>
<string key="managePlugins:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="getNewPlugins:">
<string key="name">getNewPlugins:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="hideThisMenu:">
<string key="name">hideThisMenu:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="managePlugins:">
<string key="name">managePlugins:</string>
<string key="candidateClassName">id</string>
Expand Down
38 changes: 32 additions & 6 deletions FlashlightApp/SIMBL Agent/UIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface UIManager () <NSMenuDelegate>
@property (nonatomic) NSStatusItem *statusItem;
@property (nonatomic) IBOutlet NSMenu *statusMenu;
@property (nonatomic) IBOutlet NSMenu *pluginExamples;
@property (nonatomic) BOOL statusItemShown;

@end

Expand All @@ -23,12 +24,33 @@ @implementation UIManager
- (void)awakeFromNib {
[super awakeFromNib];

self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
[self.statusItem setHighlightMode:YES];
NSImage *image = [NSImage imageNamed:@"StatusItemOn"];
[image setTemplate:YES];
self.statusItem.image = image;
self.statusItem.menu = self.statusMenu;
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(settingsChanged:) name:@"com.nateparrott.Flashlight.DefaultsChanged" object:@"com.nateparrott.Flashlight"];
[self settingsChanged:nil];
}

- (void)settingsChanged:(id)notif {
NSLog(@"SETTINGS CHANGED");
CFPreferencesAppSynchronize(CFSTR("com.nateparrott.Flashlight"));
Boolean exists;
Boolean showMenuItem = CFPreferencesGetAppBooleanValue(CFSTR("ShowMenuItem"), CFSTR("com.nateparrott.Flashlight"), &exists);
self.statusItemShown = showMenuItem || !exists;
}

- (void)setStatusItemShown:(BOOL)statusItemShown {
if (statusItemShown != _statusItemShown) {
_statusItemShown = statusItemShown;
if (statusItemShown) {
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
[self.statusItem setHighlightMode:YES];
NSImage *image = [NSImage imageNamed:@"StatusItemOn"];
[image setTemplate:YES];
self.statusItem.image = image;
self.statusItem.menu = self.statusMenu;
} else {
[[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];
self.statusItem = nil;
}
}
}

- (IBAction)managePlugins:(id)sender {
Expand Down Expand Up @@ -79,4 +101,8 @@ - (void)openExample:(NSMenuItem *)sender {

}

- (IBAction)hideThisMenu:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"flashlight://preferences/menuBarItem"]];
}

@end
4 changes: 2 additions & 2 deletions FlashlightApp/SIMBL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
INSTALL_PATH = "";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_NAME = "$(TARGET_NAME)";
PRODUCT_VERSION = 9;
PRODUCT_VERSION = 10;
};
name = Debug;
};
Expand All @@ -425,7 +425,7 @@
INSTALL_PATH = "";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_NAME = "$(TARGET_NAME)";
PRODUCT_VERSION = 9;
PRODUCT_VERSION = 10;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>12</string>
<string>13</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Nate Parrott. All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
Binary file added flashlightplugins/static/images/Icon-Large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified flashlightplugins/static/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 50e3a0f

Please sign in to comment.