diff --git a/Loading/AppDelegate.h b/Loading/AppDelegate.h index 71a927d..2ef0820 100644 --- a/Loading/AppDelegate.h +++ b/Loading/AppDelegate.h @@ -22,6 +22,8 @@ @property NSMutableArray *processes; @property NSMutableArray *sources; @property NSMutableArray *ignore; +@property NSDictionary *mapping; + @property NSTimer *starter; @property BOOL started; diff --git a/Loading/AppDelegate.m b/Loading/AppDelegate.m index ae8d290..3248e9e 100644 --- a/Loading/AppDelegate.m +++ b/Loading/AppDelegate.m @@ -30,6 +30,7 @@ @implementation AppDelegate @synthesize processes; @synthesize sources; @synthesize ignore; +@synthesize mapping; @synthesize starter; @synthesize started; @@ -249,45 +250,38 @@ - (void)start { // find the parent app // Looks like there are a few simple rules: - // 1. first check for the first occurrence of ".app/" within the process' path - NSRange range = [path rangeOfString:@".app/"]; - if (range.location != NSNotFound) { - path = [path substringWithRange:NSMakeRange(0, range.location + range.length - 1)]; - app = [AppRecord findByPath:path within:apps atIndex:&app_index]; + + // 1. first check the manual mapping from processes to apps + NSString *path2 = nil; + + for (id prefix in mapping) { + if ([path hasPrefix:prefix]) { + path2 = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:[mapping objectForKey:prefix]]; + if (path2 != nil) break; + } + } + + if (path2 != nil) { + app = [AppRecord findByPath:path2 within:apps atIndex:&app_index]; if (app == nil) { // add this app! - app = [[AppRecord alloc] initWithPath:path]; + app = [[AppRecord alloc] initWithPath:path2]; app.animate = ![self isPathIgnored:app.path]; [apps insertObject:app atIndex:app_index]; } } - // 2. if that fails, if the name is in the format "com.apple.Safari.whatever", get the bundle matching that bundle ID + // 2. then check for the first occurrence of ".app/" within the process' path if (app == nil) { - if ([path rangeOfString:@"com.apple.Safari"].location != NSNotFound - || [path rangeOfString:@"com.apple.WebKit"].location != NSNotFound - || [path hasPrefix:@"/System/Library/StagedFrameworks/Safari/"]) { - - NSString *path2 = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.Safari"]; - if (path2 != nil) { - app = [AppRecord findByPath:path2 within:apps atIndex:&app_index]; - if (app == nil) { - // add this app! - app = [[AppRecord alloc] initWithPath:path2]; - app.animate = ![self isPathIgnored:app.path]; - [apps insertObject:app atIndex:app_index]; - } - } - } else if ([path hasPrefix:@"/System/Library/PrivateFrameworks/CommerceKit.framework/"]) { - NSString *path2 = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.AppStore"]; - if (path2 != nil) { - app = [AppRecord findByPath:path2 within:apps atIndex:&app_index]; - if (app == nil) { - // add this app! - app = [[AppRecord alloc] initWithPath:path2]; - app.animate = ![self isPathIgnored:app.path]; - [apps insertObject:app atIndex:app_index]; - } + NSRange range = [path rangeOfString:@".app/" options:NSBackwardsSearch]; + if (range.location != NSNotFound) { + path = [path substringWithRange:NSMakeRange(0, range.location + range.length - 1)]; + app = [AppRecord findByPath:path within:apps atIndex:&app_index]; + if (app == nil) { + // add this app! + app = [[AppRecord alloc] initWithPath:path]; + app.animate = ![self isPathIgnored:app.path]; + [apps insertObject:app atIndex:app_index]; } } } @@ -321,8 +315,12 @@ - (void)start { source2.up = up; source2.down = down; process.updated = CFAbsoluteTimeGetCurrent(); + + // when Loading first launches we have no way of knowing which apps used the network recently, + // so give it five seconds to use the network again or it goes straight to the Loaded section if (!started) process.updated -= (LOADED_TIME - 5 * 60); + if (process.app != nil) process.app.updated = process.updated; } @@ -394,6 +392,16 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { processes = [[NSMutableArray alloc] initWithCapacity:0]; sources = [[NSMutableArray alloc] initWithCapacity:0]; + mapping = @{ + @"/System/Library/StagedFrameworks/Safari/" : @"com.apple.Safari", + @"/System/Library/PrivateFrameworks/Safari.framework/" : @"com.apple.Safari", + @"/System/Library/PrivateFrameworks/SafariServices.framework/" : @"com.apple.Safari", + @"/System/Library/Frameworks/WebKit.framework/" : @"com.apple.Safari", + @"/System/Library/PrivateFrameworks/CommerceKit.framework/" : @"com.apple.AppStore", + @"/System/Library/Frameworks/AddressBook.framework/" : @"com.apple.AddressBook", + @"/Library/Application Support/Adobe/Flash Player Install Manager/" : @"com.adobe.flashplayer.installmanager" + }; + disabled = [NSImage imageNamed:@"Disabled"]; [disabled setTemplate:YES]; diff --git a/Loading/Info.plist b/Loading/Info.plist index ac36109..dce3438 100644 --- a/Loading/Info.plist +++ b/Loading/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0.2 + 1.1 CFBundleSignature BNZI CFBundleVersion - 566 + 569 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion