Skip to content

Commit

Permalink
Trying out a new menu icon
Browse files Browse the repository at this point in the history
The new icon is a bit smaller and bolder than the old one, which should
hopefully address the complaints about it being too hard to see against
some backgrounds.
  • Loading branch information
Mike McFadden committed May 8, 2015
1 parent 122d745 commit 582489f
Show file tree
Hide file tree
Showing 111 changed files with 472 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<key>IDESourceControlProjectIdentifier</key>
<string>1FB2C5B4-D727-4FC7-A7DD-6EE5FDCCE558</string>
<key>IDESourceControlProjectName</key>
<string>Loading</string>
<string>project</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>4B572F18C614D46C0A45147ECDFBA42C28BCDA4E</key>
<string>https://github.com/BonzaiThePenguin/Loading.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Loading.xcodeproj</string>
<string>Loading.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>4B572F18C614D46C0A45147ECDFBA42C28BCDA4E</key>
Expand Down
Binary file not shown.
5 changes: 4 additions & 1 deletion Loading/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

@property NSTimer *animator;
@property NSImage *disabled;
@property NSArray *frames;
@property NSImage *disabledInverted;
@property NSArray *normal;
@property NSArray *inverted;
@property int frame;
@property BOOL animating;
@property BOOL darkMode;

@property NSMutableArray *apps;
@property NSMutableArray *processes;
Expand Down
73 changes: 54 additions & 19 deletions Loading/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ @implementation AppDelegate

@synthesize animator;
@synthesize disabled;
@synthesize frames;
@synthesize disabledInverted;
@synthesize normal;
@synthesize inverted;
@synthesize frame;
@synthesize animating;
@synthesize darkMode;

@synthesize apps;
@synthesize processes;
Expand All @@ -51,12 +54,30 @@ - (NSButton *)statusItemButton {
return nil;
}

- (BOOL)isDarkMode {
NSDictionary *domain = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
if (domain != nil) {
NSString *style = [domain valueForKey:@"AppleInterfaceStyle"];
if (style != nil) return [style isEqualToString:@"Dark"];
}
return false;
}

// setImage is deprecated, but is only called in 10.9 or older where it was not deprecated
- (void)setImage:(NSImage *)image {
if ([statusItem respondsToSelector:@selector(button)])
[[statusItem button] setImage:image];
else
[statusItem setImage:image];
- (void)setImage:(NSImage *)image alternate:(NSImage *)alternate {
if ([statusItem respondsToSelector:@selector(button)]) {
if (darkMode)
[[statusItem button] setImage:alternate];
else
[[statusItem button] setImage:image];
[[statusItem button] setAlternateImage:alternate];
} else {
if (darkMode)
[statusItem setImage:alternate];
else
[statusItem setImage:image];
[statusItem setAlternateImage:alternate];
}
}

- (void)showDialog {
Expand Down Expand Up @@ -351,6 +372,16 @@ - (void)start {
}


- (void)themeChanged:(NSNotification *)notification {
darkMode = [self isDarkMode];

// update the app icon!
if (animating)
[self setImage:[normal objectAtIndex:frame] alternate:[inverted objectAtIndex:frame]];
else
[self setImage:disabled alternate:disabledInverted];
}

// NSStatusItem's menu will be drawn in the wrong position if you follow the recommended behavior
// of using [NSMenuDelegate menuNeedsUpdate:] OR [NSMenuDelegate menu:updateItem:atIndex:shouldCancel:]
// The only workaround I was able to find was swizzling this selector and updating the menu here
Expand All @@ -373,6 +404,8 @@ - (void)beginTracking:(NSNotification *)notification {
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
_sharedDelegate = self;

darkMode = [self isDarkMode];

NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
[preferences registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:NO, @"Loaded", nil]];

Expand Down Expand Up @@ -406,18 +439,17 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
};

disabled = [NSImage imageNamed:@"Disabled"];
[disabled setTemplate:YES];
disabledInverted = [NSImage imageNamed:@"DisabledInverted"];

frames = [[NSArray alloc] initWithObjects:[NSImage imageNamed:@"Frame1"], [NSImage imageNamed:@"Frame2"], [NSImage imageNamed:@"Frame3"],
[NSImage imageNamed:@"Frame4"], [NSImage imageNamed:@"Frame5"], [NSImage imageNamed:@"Frame6"],
[NSImage imageNamed:@"Frame7"], [NSImage imageNamed:@"Frame8"], [NSImage imageNamed:@"Frame9"],
[NSImage imageNamed:@"Frame10"], [NSImage imageNamed:@"Frame11"], [NSImage imageNamed:@"Frame12"], nil];
normal = [[NSArray alloc] initWithObjects:[NSImage imageNamed:@"Normal1"], [NSImage imageNamed:@"Normal2"], [NSImage imageNamed:@"Normal3"],
[NSImage imageNamed:@"Normal4"], [NSImage imageNamed:@"Normal5"], [NSImage imageNamed:@"Normal6"],
[NSImage imageNamed:@"Normal7"], [NSImage imageNamed:@"Normal8"], [NSImage imageNamed:@"Normal9"],
[NSImage imageNamed:@"Normal10"], [NSImage imageNamed:@"Normal11"], [NSImage imageNamed:@"Normal12"], nil];

long frame_index;
for (frame_index = 0; frame_index < [frames count]; frame_index++) {
NSImage *image = [frames objectAtIndex:frame_index];
[image setTemplate:YES];
}
inverted = [[NSArray alloc] initWithObjects:[NSImage imageNamed:@"Inverted1"], [NSImage imageNamed:@"Inverted2"], [NSImage imageNamed:@"Inverted3"],
[NSImage imageNamed:@"Inverted4"], [NSImage imageNamed:@"Inverted5"], [NSImage imageNamed:@"Inverted6"],
[NSImage imageNamed:@"Inverted7"], [NSImage imageNamed:@"Inverted8"], [NSImage imageNamed:@"Inverted9"],
[NSImage imageNamed:@"Inverted10"], [NSImage imageNamed:@"Inverted11"], [NSImage imageNamed:@"Inverted12"], nil];

animator = nil;
animating = YES; frame = 0;
Expand All @@ -427,6 +459,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[statusItem setMenu:menu];
menuDelegate = [[MenuDelegate alloc] init];

// add a notification observer for when the user changes between light theme and dark theme
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];

// swizzle NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp to avoid a bug with menu positioning (see above)
_trackMouse_original = method_setImplementation(class_getInstanceMethod([[[self statusItemButton] cell] class], @selector(trackMouse:inRect:ofView:untilMouseUp:)), (IMP)_trackMouse_replacement);

Expand Down Expand Up @@ -505,8 +540,8 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification {
}

- (void)updateAnimation {
[self setImage:[frames objectAtIndex:frame]];
if (animating && ++frame >= [frames count]) frame = 0;
[self setImage:[normal objectAtIndex:frame] alternate:[inverted objectAtIndex:frame]];
if (animating && ++frame >= [normal count]) frame = 0;
}

- (void)startAnimating {
Expand All @@ -523,7 +558,7 @@ - (void)stopAnimating {
animator = nil;
}

[self setImage:disabled];
[self setImage:disabled alternate:disabledInverted];
}

@end
4 changes: 2 additions & 2 deletions Loading/Images.xcassets/Disabled.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "disabled.png"
"filename" : "Disabled.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "disabled@2x.png"
"filename" : "Disabled@2x.png"
},
{
"idiom" : "universal",
Expand Down
Binary file modified Loading/Images.xcassets/Disabled.imageset/disabled.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 Loading/Images.xcassets/Disabled.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Loading/Images.xcassets/DisabledInverted.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "DisabledInverted.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Loading/Images.xcassets/Frame1.imageset/normal1.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed Loading/Images.xcassets/Frame2.imageset/normal2.png
Binary file not shown.
Binary file not shown.
Binary file removed Loading/Images.xcassets/Frame3.imageset/normal3.png
Binary file not shown.
Binary file not shown.
Binary file removed Loading/Images.xcassets/Frame4.imageset/normal4.png
Binary file not shown.
Binary file not shown.
22 changes: 0 additions & 22 deletions Loading/Images.xcassets/Frame5.imageset/Contents.json

This file was deleted.

Binary file removed Loading/Images.xcassets/Frame5.imageset/normal5.png
Binary file not shown.
Binary file not shown.
22 changes: 0 additions & 22 deletions Loading/Images.xcassets/Frame6.imageset/Contents.json

This file was deleted.

Binary file removed Loading/Images.xcassets/Frame6.imageset/normal6.png
Binary file not shown.
Binary file not shown.
22 changes: 0 additions & 22 deletions Loading/Images.xcassets/Frame7.imageset/Contents.json

This file was deleted.

Binary file removed Loading/Images.xcassets/Frame7.imageset/normal7.png
Binary file not shown.
Binary file not shown.
22 changes: 0 additions & 22 deletions Loading/Images.xcassets/Frame8.imageset/Contents.json

This file was deleted.

Binary file removed Loading/Images.xcassets/Frame8.imageset/normal8.png
Binary file not shown.
Diff not rendered.
22 changes: 0 additions & 22 deletions Loading/Images.xcassets/Frame9.imageset/Contents.json

This file was deleted.

Binary file removed Loading/Images.xcassets/Frame9.imageset/normal9.png
Diff not rendered.
Diff not rendered.
22 changes: 22 additions & 0 deletions Loading/Images.xcassets/Inverted1.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "Inverted1.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
22 changes: 22 additions & 0 deletions Loading/Images.xcassets/Inverted10.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "Inverted10.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
22 changes: 22 additions & 0 deletions Loading/Images.xcassets/Inverted11.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "Inverted11.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading

0 comments on commit 582489f

Please sign in to comment.