Skip to content

Commit 50e3a0f

Browse files
committed
allow hiding the menu bar item
1 parent b477213 commit 50e3a0f

File tree

9 files changed

+144
-25
lines changed

9 files changed

+144
-25
lines changed

FlashlightApp/EasySIMBL/AppDelegate.m

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ @interface AppDelegate ()
2020
@property (nonatomic,weak) IBOutlet NSMenuItem *createNewAutomatorPluginMenuItem;
2121
@property (nonatomic,weak) IBOutlet NSTextField *versionLabel, *searchAnything;
2222
@property (nonatomic,weak) IBOutlet NSButton *openGithub, *requestPlugin, *leaveFeedback;
23+
@property (nonatomic,weak) IBOutlet NSWindow *aboutWindow;
24+
@property (nonatomic,weak) IBOutlet NSButton *menuBarItemPreferenceButton;
2325

2426
@end
2527

@@ -47,7 +49,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
4749

4850
[self checkSpotlightVersion];
4951

50-
[self setupURLHandling];
52+
[self setupDefaults];
5153

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

@@ -116,8 +118,13 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
116118
self.openGithub.stringValue = NSLocalizedString(@"Contribute on GitHub", @"");
117119
self.requestPlugin.stringValue = NSLocalizedString(@"Request a Plugin", @"");
118120
self.searchAnything.stringValue = NSLocalizedString(@"Search anything.", @"");
121+
self.menuBarItemPreferenceButton.stringValue = NSLocalizedString(@"Show menu bar item", @"");
122+
[self.menuBarItemPreferenceButton sizeToFit];
123+
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);
119124

120125
[UpdateChecker shared]; // begin fetch
126+
127+
[self setupURLHandling];
121128
}
122129

123130
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
@@ -300,7 +307,34 @@ - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEv
300307
[self.pluginListController showCategory:parts[1]];
301308
} else if (parts.count == 1 && [parts[0] isEqualToString:@"search"]) {
302309
[self.pluginListController showSearch:query[@"q"]];
310+
} else if (parts.count >= 1 && [parts[0] isEqualToString:@"preferences"]) {
311+
if (parts.count == 2 && [parts[1] isEqualToString:@"menuBarItem"]) {
312+
[self.aboutWindow makeKeyAndOrderFront:nil];
313+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
314+
// in case we're mid-launch — we don't want the main window to be made key above this window
315+
[self.aboutWindow makeKeyAndOrderFront:nil];
316+
});
317+
}
303318
}
304319
}
305320
}
321+
#pragma mark Preferences
322+
- (void)setupDefaults {
323+
NSDictionary *defaults = @{
324+
@"ShowMenuItem": @YES
325+
};
326+
for (NSString *key in defaults) {
327+
if (![[NSUserDefaults standardUserDefaults] valueForKey:key]) {
328+
[[NSUserDefaults standardUserDefaults] setValue:defaults[key] forKey:key];
329+
}
330+
}
331+
}
332+
333+
- (IBAction)showMenuBarItemPressed:(id)sender {
334+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
335+
[[NSUserDefaults standardUserDefaults] synchronize];
336+
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.nateparrott.Flashlight.DefaultsChanged" object:@"com.nateparrott.Flashlight" userInfo:nil options:NSNotificationPostToAllSessions | NSNotificationDeliverImmediately];
337+
});
338+
}
339+
306340
@end

FlashlightApp/EasySIMBL/Base.lproj/MainMenu.xib

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@
348348
</menu>
349349
<customObject id="494" customClass="AppDelegate">
350350
<connections>
351+
<outlet property="aboutWindow" destination="Nbs-13-Twb" id="JQi-Kg-U2G"/>
351352
<outlet property="leaveFeedback" destination="YyB-xf-RjT" id="MGc-ch-NJm"/>
353+
<outlet property="menuBarItemPreferenceButton" destination="Llk-bz-SPb" id="grz-AH-VkL"/>
352354
<outlet property="openGithub" destination="no0-HV-O9k" id="12n-tY-kFy"/>
353355
<outlet property="pluginListController" destination="715" id="OyI-Qw-pUc"/>
354356
<outlet property="requestPlugin" destination="QeJ-hd-3A1" id="AK4-6B-Nzq"/>
@@ -591,23 +593,23 @@
591593
<point key="canvasLocation" x="202.5" y="588"/>
592594
</customView>
593595
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="Nbs-13-Twb" userLabel="About">
594-
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
596+
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
595597
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
596-
<rect key="contentRect" x="109" y="138" width="242" height="333"/>
598+
<rect key="contentRect" x="109" y="138" width="242" height="361"/>
597599
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="800"/>
598600
<value key="minSize" type="size" width="242" height="260"/>
599601
<value key="maxSize" type="size" width="242" height="260"/>
600602
<view key="contentView" id="ML2-hK-xgc">
601-
<rect key="frame" x="0.0" y="-1" width="242" height="333"/>
603+
<rect key="frame" x="0.0" y="-5" width="242" height="361"/>
602604
<autoresizingMask key="autoresizingMask"/>
603605
<subviews>
604606
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="bs8-1N-RgN">
605-
<rect key="frame" x="75" y="221" width="92" height="92"/>
607+
<rect key="frame" x="75" y="249" width="92" height="92"/>
606608
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
607609
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="Icon" id="QLY-QW-30e"/>
608610
</imageView>
609611
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="b4m-8B-Vhn">
610-
<rect key="frame" x="18" y="161" width="206" height="30"/>
612+
<rect key="frame" x="18" y="189" width="206" height="30"/>
611613
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
612614
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Flashlight" id="CKY-mr-H4g">
613615
<font key="font" size="25" name="HelveticaNeue-Light"/>
@@ -616,7 +618,7 @@
616618
</textFieldCell>
617619
</textField>
618620
<button id="no0-HV-O9k">
619-
<rect key="frame" x="38" y="82" width="166" height="29"/>
621+
<rect key="frame" x="38" y="110" width="166" height="29"/>
620622
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
621623
<buttonCell key="cell" type="bevel" title="Contribute on GitHub" bezelStyle="regularSquare" alignment="center" borderStyle="border" inset="2" id="P0e-Mj-nLE">
622624
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -627,7 +629,7 @@
627629
</connections>
628630
</button>
629631
<button id="YyB-xf-RjT">
630-
<rect key="frame" x="38" y="50" width="166" height="29"/>
632+
<rect key="frame" x="38" y="78" width="166" height="29"/>
631633
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
632634
<buttonCell key="cell" type="bevel" title="Leave Feedback" bezelStyle="regularSquare" alignment="center" borderStyle="border" inset="2" id="NO4-GD-LyW">
633635
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -638,7 +640,7 @@
638640
</connections>
639641
</button>
640642
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="gNj-56-AoU">
641-
<rect key="frame" x="18" y="123" width="206" height="17"/>
643+
<rect key="frame" x="18" y="151" width="206" height="17"/>
642644
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
643645
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Search anything." id="Zut-6I-UVj">
644646
<font key="font" metaFont="system"/>
@@ -647,7 +649,7 @@
647649
</textFieldCell>
648650
</textField>
649651
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="v99-pH-dRh">
650-
<rect key="frame" x="18" y="145" width="206" height="11"/>
652+
<rect key="frame" x="18" y="173" width="206" height="11"/>
651653
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
652654
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Version ?.??" id="kFB-vx-lDm">
653655
<font key="font" metaFont="miniSystem"/>
@@ -656,7 +658,7 @@
656658
</textFieldCell>
657659
</textField>
658660
<button id="QeJ-hd-3A1">
659-
<rect key="frame" x="38" y="17" width="166" height="29"/>
661+
<rect key="frame" x="38" y="45" width="166" height="29"/>
660662
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
661663
<buttonCell key="cell" type="bevel" title="Request a Plugin" bezelStyle="regularSquare" alignment="center" borderStyle="border" inset="2" id="b4y-N1-H7G">
662664
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -666,9 +668,21 @@
666668
<action selector="requestAPlugin:" target="494" id="zBI-z8-sAl"/>
667669
</connections>
668670
</button>
671+
<button id="Llk-bz-SPb">
672+
<rect key="frame" x="38" y="18" width="166" height="18"/>
673+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
674+
<buttonCell key="cell" type="check" title="Show menu bar icon" bezelStyle="regularSquare" imagePosition="left" alignment="center" state="on" inset="2" id="AtZ-Rw-Wyh">
675+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
676+
<font key="font" metaFont="system"/>
677+
</buttonCell>
678+
<connections>
679+
<action selector="showMenuBarItemPressed:" target="494" id="ykO-0C-Nv9"/>
680+
<binding destination="702" name="value" keyPath="values.ShowMenuItem" id="PE1-lx-tPa"/>
681+
</connections>
682+
</button>
669683
</subviews>
670684
</view>
671-
<point key="canvasLocation" x="-242" y="521.5"/>
685+
<point key="canvasLocation" x="-242" y="535.5"/>
672686
</window>
673687
<scrollView autohidesScrollers="YES" horizontalLineScroll="96" horizontalPageScroll="10" verticalLineScroll="96" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="IJ7-m0-7jG" userLabel="Plugin List">
674688
<rect key="frame" x="0.0" y="0.0" width="454" height="448"/>

FlashlightApp/EasySIMBL/Flashlight-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<key>CFBundlePackageType</key>
3939
<string>APPL</string>
4040
<key>CFBundleShortVersionString</key>
41-
<string>0.97.0</string>
41+
<string>0.97.1</string>
4242
<key>CFBundleSignature</key>
4343
<string>????</string>
4444
<key>CFBundleURLTypes</key>
@@ -65,7 +65,7 @@
6565
</dict>
6666
</array>
6767
<key>CFBundleVersion</key>
68-
<string>41</string>
68+
<string>42</string>
6969
<key>LSApplicationCategoryType</key>
7070
<string>public.app-category.utilities</string>
7171
<key>LSMinimumSystemVersion</key>

FlashlightApp/SIMBL Agent/Base.lproj/MainMenu.xib

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,12 +1163,30 @@
11631163
<reference key="NSOnImage" ref="35465992"/>
11641164
<reference key="NSMixedImage" ref="502551668"/>
11651165
<string key="NSAction">submenuAction:</string>
1166-
<reference key="NSTarget"/>
1166+
<reference key="NSTarget" ref="701433788"/>
11671167
<object class="NSMenu" key="NSSubmenu" id="701433788">
11681168
<string key="NSTitle"/>
11691169
<array class="NSMutableArray" key="NSMenuItems"/>
11701170
</object>
11711171
</object>
1172+
<object class="NSMenuItem" id="191023024">
1173+
<reference key="NSMenu" ref="1043790343"/>
1174+
<bool key="NSIsDisabled">YES</bool>
1175+
<bool key="NSIsSeparator">YES</bool>
1176+
<string key="NSTitle"/>
1177+
<string key="NSKeyEquiv"/>
1178+
<int key="NSMnemonicLoc">2147483647</int>
1179+
<reference key="NSOnImage" ref="35465992"/>
1180+
<reference key="NSMixedImage" ref="502551668"/>
1181+
</object>
1182+
<object class="NSMenuItem" id="1004967477">
1183+
<reference key="NSMenu" ref="1043790343"/>
1184+
<string key="NSTitle">Hide this menu...</string>
1185+
<string key="NSKeyEquiv"/>
1186+
<int key="NSMnemonicLoc">2147483647</int>
1187+
<reference key="NSOnImage" ref="35465992"/>
1188+
<reference key="NSMixedImage" ref="502551668"/>
1189+
</object>
11721190
</array>
11731191
</object>
11741192
</array>
@@ -1702,6 +1720,14 @@
17021720
</object>
17031721
<int key="connectionID">475</int>
17041722
</object>
1723+
<object class="IBConnectionRecord">
1724+
<object class="IBActionConnection" key="connection">
1725+
<string key="label">hideThisMenu:</string>
1726+
<reference key="source" ref="319322392"/>
1727+
<reference key="destination" ref="1004967477"/>
1728+
</object>
1729+
<int key="connectionID">480</int>
1730+
</object>
17051731
<object class="IBConnectionRecord">
17061732
<object class="IBOutletConnection" key="connection">
17071733
<string key="label">delegate</string>
@@ -2568,6 +2594,8 @@
25682594
<reference ref="847989738"/>
25692595
<reference ref="706656518"/>
25702596
<reference ref="412134391"/>
2597+
<reference ref="1004967477"/>
2598+
<reference ref="191023024"/>
25712599
</array>
25722600
<reference key="parent" ref="0"/>
25732601
</object>
@@ -2610,6 +2638,16 @@
26102638
<array class="NSMutableArray" key="children"/>
26112639
<reference key="parent" ref="412134391"/>
26122640
</object>
2641+
<object class="IBObjectRecord">
2642+
<int key="objectID">478</int>
2643+
<reference key="object" ref="1004967477"/>
2644+
<reference key="parent" ref="1043790343"/>
2645+
</object>
2646+
<object class="IBObjectRecord">
2647+
<int key="objectID">479</int>
2648+
<reference key="object" ref="191023024"/>
2649+
<reference key="parent" ref="1043790343"/>
2650+
</object>
26132651
</array>
26142652
</object>
26152653
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -2732,6 +2770,8 @@
27322770
<string key="463.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
27332771
<string key="468.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
27342772
<string key="471.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
2773+
<string key="478.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
2774+
<string key="479.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
27352775
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
27362776
<string key="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
27372777
<string key="57.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2753,7 +2793,7 @@
27532793
<nil key="activeLocalization"/>
27542794
<dictionary class="NSMutableDictionary" key="localizations"/>
27552795
<nil key="sourceID"/>
2756-
<int key="maxID">477</int>
2796+
<int key="maxID">480</int>
27572797
</object>
27582798
<object class="IBClassDescriber" key="IBDocument.Classes">
27592799
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2777,13 +2817,18 @@
27772817
<string key="className">UIManager</string>
27782818
<dictionary class="NSMutableDictionary" key="actions">
27792819
<string key="getNewPlugins:">id</string>
2820+
<string key="hideThisMenu:">id</string>
27802821
<string key="managePlugins:">id</string>
27812822
</dictionary>
27822823
<dictionary class="NSMutableDictionary" key="actionInfosByName">
27832824
<object class="IBActionInfo" key="getNewPlugins:">
27842825
<string key="name">getNewPlugins:</string>
27852826
<string key="candidateClassName">id</string>
27862827
</object>
2828+
<object class="IBActionInfo" key="hideThisMenu:">
2829+
<string key="name">hideThisMenu:</string>
2830+
<string key="candidateClassName">id</string>
2831+
</object>
27872832
<object class="IBActionInfo" key="managePlugins:">
27882833
<string key="name">managePlugins:</string>
27892834
<string key="candidateClassName">id</string>

FlashlightApp/SIMBL Agent/UIManager.m

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ @interface UIManager () <NSMenuDelegate>
1515
@property (nonatomic) NSStatusItem *statusItem;
1616
@property (nonatomic) IBOutlet NSMenu *statusMenu;
1717
@property (nonatomic) IBOutlet NSMenu *pluginExamples;
18+
@property (nonatomic) BOOL statusItemShown;
1819

1920
@end
2021

@@ -23,12 +24,33 @@ @implementation UIManager
2324
- (void)awakeFromNib {
2425
[super awakeFromNib];
2526

26-
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
27-
[self.statusItem setHighlightMode:YES];
28-
NSImage *image = [NSImage imageNamed:@"StatusItemOn"];
29-
[image setTemplate:YES];
30-
self.statusItem.image = image;
31-
self.statusItem.menu = self.statusMenu;
27+
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(settingsChanged:) name:@"com.nateparrott.Flashlight.DefaultsChanged" object:@"com.nateparrott.Flashlight"];
28+
[self settingsChanged:nil];
29+
}
30+
31+
- (void)settingsChanged:(id)notif {
32+
NSLog(@"SETTINGS CHANGED");
33+
CFPreferencesAppSynchronize(CFSTR("com.nateparrott.Flashlight"));
34+
Boolean exists;
35+
Boolean showMenuItem = CFPreferencesGetAppBooleanValue(CFSTR("ShowMenuItem"), CFSTR("com.nateparrott.Flashlight"), &exists);
36+
self.statusItemShown = showMenuItem || !exists;
37+
}
38+
39+
- (void)setStatusItemShown:(BOOL)statusItemShown {
40+
if (statusItemShown != _statusItemShown) {
41+
_statusItemShown = statusItemShown;
42+
if (statusItemShown) {
43+
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
44+
[self.statusItem setHighlightMode:YES];
45+
NSImage *image = [NSImage imageNamed:@"StatusItemOn"];
46+
[image setTemplate:YES];
47+
self.statusItem.image = image;
48+
self.statusItem.menu = self.statusMenu;
49+
} else {
50+
[[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];
51+
self.statusItem = nil;
52+
}
53+
}
3254
}
3355

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

80102
}
81103

104+
- (IBAction)hideThisMenu:(id)sender {
105+
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"flashlight://preferences/menuBarItem"]];
106+
}
107+
82108
@end

FlashlightApp/SIMBL.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@
411411
INSTALL_PATH = "";
412412
MACOSX_DEPLOYMENT_TARGET = 10.10;
413413
PRODUCT_NAME = "$(TARGET_NAME)";
414-
PRODUCT_VERSION = 9;
414+
PRODUCT_VERSION = 10;
415415
};
416416
name = Debug;
417417
};
@@ -425,7 +425,7 @@
425425
INSTALL_PATH = "";
426426
MACOSX_DEPLOYMENT_TARGET = 10.10;
427427
PRODUCT_NAME = "$(TARGET_NAME)";
428-
PRODUCT_VERSION = 9;
428+
PRODUCT_VERSION = 10;
429429
};
430430
name = Release;
431431
};

FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>12</string>
22+
<string>13</string>
2323
<key>NSHumanReadableCopyright</key>
2424
<string>Copyright © 2014 Nate Parrott. All rights reserved.</string>
2525
<key>NSPrincipalClass</key>
200 KB
Loading
631 Bytes
Loading

0 commit comments

Comments
 (0)