Skip to content

Commit

Permalink
Adding a manual mapping of processes to apps
Browse files Browse the repository at this point in the history
Sometimes there doesn’t seem to be any connection between a process and
the app it really belongs to, so have a manual mapping of those
processes to the correct apps.
  • Loading branch information
Mike McFadden committed May 7, 2015
1 parent cc6914b commit ed59010
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
2 changes: 2 additions & 0 deletions Loading/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@property NSMutableArray *processes;
@property NSMutableArray *sources;
@property NSMutableArray *ignore;
@property NSDictionary *mapping;

@property NSTimer *starter;
@property BOOL started;

Expand Down
70 changes: 39 additions & 31 deletions Loading/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ @implementation AppDelegate
@synthesize processes;
@synthesize sources;
@synthesize ignore;
@synthesize mapping;

@synthesize starter;
@synthesize started;
Expand Down Expand Up @@ -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];
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions Loading/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.2</string>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>BNZI</string>
<key>CFBundleVersion</key>
<string>566</string>
<string>569</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit ed59010

Please sign in to comment.