Skip to content
Browse files

Added an option, based in spirit on the patches from Chris Farber, which

make the status item optional.

If you turn off "Show in Menu Bar", Scrollvetica will suppress the status
item when it is launched as a login item. (This should cover nearly all of
the cases where people want to hide the status item, while still making it
behave reasonably for quick interactive use and trying out.)

If the status item is hidden, double-clicking the Scrollvetica icon in the
finder will make it visible again.
  • Loading branch information...
1 parent 77307d5 commit 28e8075452841edf697a0c113868b85cbb0ecf2c @correia committed
View
37 Resources/English.lproj/MainMenu.xib
@@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1060</int>
- <string key="IBDocument.SystemVersion">10J567</string>
+ <string key="IBDocument.SystemVersion">10J869</string>
<string key="IBDocument.InterfaceBuilderVersion">1305</string>
<string key="IBDocument.AppKitVersion">1038.35</string>
- <string key="IBDocument.HIToolboxVersion">462.00</string>
+ <string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">1305</string>
@@ -404,6 +404,14 @@
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
+ <object class="NSMenuItem" id="445270881">
+ <reference key="NSMenu" ref="1002232010"/>
+ <string key="NSTitle"> Show in Menu Bar</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="35465992"/>
+ <reference key="NSMixedImage" ref="502551668"/>
+ </object>
<object class="NSMenuItem" id="815981090">
<reference key="NSMenu" ref="1002232010"/>
<string key="NSTitle">Invert Scroll Events</string>
@@ -636,6 +644,14 @@
</object>
<int key="connectionID">576</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">toggleShowsStatusItem:</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="445270881"/>
+ </object>
+ <int key="connectionID">592</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -933,6 +949,7 @@
<reference ref="401588875"/>
<reference ref="629501322"/>
<reference ref="815981090"/>
+ <reference ref="445270881"/>
</object>
<reference key="parent" ref="0"/>
<string key="objectName">Status Menu</string>
@@ -967,6 +984,11 @@
<reference key="object" ref="815981090"/>
<reference key="parent" ref="1002232010"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">588</int>
+ <reference key="object" ref="445270881"/>
+ <reference key="parent" ref="1002232010"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -1055,6 +1077,7 @@
<string>57.editorWindowContentRectSynchronizationRect</string>
<string>58.IBPluginDependency</string>
<string>58.ImportedFromIB2</string>
+ <string>588.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1140,6 +1163,7 @@
<string>{{23, 794}, {245, 183}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -1154,7 +1178,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
- <int key="maxID">587</int>
+ <int key="maxID">592</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1169,12 +1193,14 @@
<string>statusItemShowAboutBox:</string>
<string>toggleInvertScrollEvents:</string>
<string>toggleLaunchAutomaticallyAtLogIn:</string>
+ <string>toggleShowsStatusItem:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
@@ -1184,6 +1210,7 @@
<string>statusItemShowAboutBox:</string>
<string>toggleInvertScrollEvents:</string>
<string>toggleLaunchAutomaticallyAtLogIn:</string>
+ <string>toggleShowsStatusItem:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1199,6 +1226,10 @@
<string key="name">toggleLaunchAutomaticallyAtLogIn:</string>
<string key="candidateClassName">id</string>
</object>
+ <object class="IBActionInfo">
+ <string key="name">toggleShowsStatusItem:</string>
+ <string key="candidateClassName">id</string>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
View
2 Scrollvetica.xcodeproj/project.pbxproj
@@ -37,6 +37,7 @@
5F7630A7132730AF00FB0E42 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Resources/English.lproj/MainMenu.xib; sourceTree = "<group>"; };
5F7630AA13273E5100FB0E42 /* LICENSE.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE.txt; sourceTree = "<group>"; };
5F7630AB13273E5100FB0E42 /* README.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
+ 5F80CA9F1359396300F94EB2 /* RELEASE_NOTES.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = RELEASE_NOTES.txt; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* Scrollvetica.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Scrollvetica.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@@ -94,6 +95,7 @@
children = (
5F7630AA13273E5100FB0E42 /* LICENSE.txt */,
5F7630AB13273E5100FB0E42 /* README.txt */,
+ 5F80CA9F1359396300F94EB2 /* RELEASE_NOTES.txt */,
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
View
3 Source/ApplicationController.h
@@ -14,6 +14,8 @@
ScrollingInverterEventTap *_eventTap;
NSStatusItem *_statusItem;
NSMenu *_statusItemMenu;
+ BOOL _wasLaunchedAtLogin;
+ BOOL _showsStatusItem;
LSSharedFileListRef _loginItemsFileList;
}
@@ -22,5 +24,6 @@
- (IBAction)statusItemShowAboutBox:(id)sender;
- (IBAction)toggleLaunchAutomaticallyAtLogIn:(id)sender;
- (IBAction)toggleInvertScrollEvents:(id)sender;
+- (IBAction)toggleShowsStatusItem:(id)sender;
@end
View
141 Source/ApplicationController.m
@@ -8,18 +8,40 @@
#import "ApplicationController.h"
#import "ScrollingInverterEventTap.h"
+static NSString *const ShowStatusItemKey = @"ShowStatusItem";
+
@interface ApplicationController ()
+@property (nonatomic) BOOL wasLaunchedAtLogin;
+
+@property (nonatomic) BOOL showsStatusItem;
+- (void)setShowsStatusItem:(BOOL)showsStatusItem updateUserDefaults:(BOOL)updateUserDefaults;
+
- (BOOL)hasLoginItemWithPath:(NSString *)path;
- (void)addLoginItemWithPath:(NSString *)path;
- (void)removeLoginItemWithPath:(NSString *)path;
- (LSSharedFileListRef)loginItemsFileList;
- (LSSharedFileListItemRef)copyLoginItemWithPath:(NSString *)path;
+- (BOOL)_wasLaunchedAtLogin;
+
@end
@implementation ApplicationController
++ (void)initialize;
+{
+ if (self != [ApplicationController class])
+ return;
+
+ NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool:YES], ShowStatusItemKey,
+ nil
+ ];
+
+ [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
+}
+
- (id)init;
{
self = [super init];
@@ -27,7 +49,8 @@ - (id)init;
return nil;
_eventTap = [[ScrollingInverterEventTap alloc] init];
-
+ _wasLaunchedAtLogin = [self _wasLaunchedAtLogin];
+
return self;
}
@@ -47,8 +70,6 @@ - (void)dealloc;
}
-@synthesize statusItemMenu = _statusItemMenu;
-
- (void)awakeFromNib;
{
NSAssert(!_statusItem, @"");
@@ -56,8 +77,8 @@ - (void)awakeFromNib;
#if !DEBUG
// -toggleInvertScrollEvents: is really only useful in debug builds
- NSInteger itemIndex = [_statusItemMenu indexOfItemWithTarget:self andAction:@selector(toggleInvertScrollEvents:)];
- [_statusItemMenu removeItemAtIndex:itemIndex];
+ NSInteger invertScrollEventsMenuItemIndex = [_statusItemMenu indexOfItemWithTarget:self andAction:@selector(toggleInvertScrollEvents:)];
+ [_statusItemMenu removeItemAtIndex:invertScrollEventsMenuItemIndex];
#endif
[_statusItem setImage:[NSImage imageNamed:@"StatusMenuIcon"]];
@@ -66,6 +87,45 @@ - (void)awakeFromNib;
[_statusItem setMenu:_statusItemMenu];
}
+@synthesize statusItemMenu = _statusItemMenu;
+
+@synthesize wasLaunchedAtLogin = _wasLaunchedAtLogin;
+
+- (BOOL)showsStatusItem;
+{
+ return _showsStatusItem;
+}
+
+- (void)setShowsStatusItem:(BOOL)showsStatusItem;
+{
+ [self setShowsStatusItem:showsStatusItem updateUserDefaults:YES];
+}
+
+- (void)setShowsStatusItem:(BOOL)showsStatusItem updateUserDefaults:(BOOL)updateUserDefaults;
+{
+ if (_showsStatusItem != showsStatusItem) {
+ _showsStatusItem = showsStatusItem;
+ if (_showsStatusItem) {
+ NSAssert(!_statusItem, @"Expected _statusItem != nil");
+ _statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:32] retain];
+ [_statusItem setImage:[NSImage imageNamed:@"StatusMenuIcon"]];
+ [_statusItem setAlternateImage:[NSImage imageNamed:@"StatusMenuIcon-Highlighted"]];
+ [_statusItem setHighlightMode:YES];
+ [_statusItem setMenu:_statusItemMenu];
+ } else {
+ NSAssert(_statusItem, @"Expected _statusItem == nil");
+ [[NSStatusBar systemStatusBar] removeStatusItem:_statusItem];
+ [_statusItem release];
+ _statusItem = nil;
+ }
+ }
+
+ if (updateUserDefaults) {
+ [[NSUserDefaults standardUserDefaults] setBool:showsStatusItem forKey:ShowStatusItemKey];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ }
+}
+
- (void)applicationDidFinishLaunching:(NSNotification *)notification;
{
SInt32 response = 0;
@@ -81,6 +141,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
[alert runModal];
[[NSApplication sharedApplication] terminate:nil];
}
+
+ BOOL shouldShowStatusItem = (self.wasLaunchedAtLogin ? [[NSUserDefaults standardUserDefaults] boolForKey:ShowStatusItemKey] : YES);
+ [self setShowsStatusItem:shouldShowStatusItem updateUserDefaults:NO];
+}
+
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag;
+{
+ if (!self.showsStatusItem) {
+ // Review: Post alert stating that we are forcing the item to visible?
+ [self setShowsStatusItem:YES updateUserDefaults:YES];
+ }
+
+ return NO;
}
- (void)applicationWillTerminate:(NSNotification *)notification;
@@ -97,6 +170,14 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
[menuItem setState:isLoginItem];
}
+ if ([menuItem action] == @selector(toggleShowsStatusItem:)) {
+ NSInteger state = self.showsStatusItem;
+ if (state == NSOffState && !self.wasLaunchedAtLogin) {
+ state = NSMixedState;
+ }
+ [menuItem setState:state];
+ }
+
if ([menuItem action] == @selector(toggleInvertScrollEvents:)) {
[menuItem setState:[_eventTap isEnabled]];
}
@@ -126,6 +207,23 @@ - (IBAction)toggleInvertScrollEvents:(id)sender;
[_eventTap setEnabled:enabled];
}
+- (IBAction)toggleShowsStatusItem:(id)sender;
+{
+ NSString *message = NSLocalizedString(@"Hide status item?", @"alert title");
+ NSString *informativeText = NSLocalizedString(@"Choosing “Hide Status Item” will permanently hide the status item. Double-click Scrollvetica in the Finder to make the status item visible again.", @"alert body");
+ NSString *defaultButton = NSLocalizedString(@"Hide Status Item", @"button title");
+ NSString *cancelButton = NSLocalizedString(@"Cancel", @"button title");
+
+ NSAlert *alert = [NSAlert alertWithMessageText:message defaultButton:defaultButton alternateButton:cancelButton otherButton:nil informativeTextWithFormat:@"%@", informativeText];
+
+ [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
+
+ if ([alert runModal] == NSAlertDefaultReturn) {
+ BOOL showsStatusItem = !self.showsStatusItem;
+ [self setShowsStatusItem:showsStatusItem updateUserDefaults:YES];
+ }
+}
+
#pragma mark -
#pragma mark Private
@@ -197,4 +295,37 @@ - (LSSharedFileListItemRef)copyLoginItemWithPath:(NSString *)path;
return foundItem;
}
+- (BOOL)_wasLaunchedAtLogin;
+{
+ OSType processLauncher = 0;
+ OSStatus status = noErr;
+ ProcessSerialNumber psn;
+ ProcessInfoRec processInfo;
+
+ status = GetCurrentProcess(&psn);
+ require_noerr(status, EXIT);
+
+ memset(&processInfo, 0, sizeof(processInfo));
+ processInfo.processInfoLength = sizeof(processInfo);
+ status = GetProcessInformation(&psn, &processInfo);
+ require_noerr(status, EXIT);
+
+ status = GetProcessInformation(&psn, &processInfo);
+ require_noerr(status, EXIT);
+
+ psn = processInfo.processLauncher;
+ status = GetProcessInformation(&psn, &processInfo);
+ require_noerr(status, EXIT);
+
+ memset(&processInfo, 0, sizeof(processInfo));
+ processInfo.processInfoLength = sizeof(processInfo);
+ status = GetProcessInformation(&psn, &processInfo);
+ require_noerr(status, EXIT);
+
+ processLauncher = processInfo.processSignature;
+
+EXIT:
+ return (processLauncher == 'lgnw');
+}
+
@end

0 comments on commit 28e8075

Please sign in to comment.
Something went wrong with that request. Please try again.