Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add System entry to apps popup #59

Merged
merged 2 commits into from Apr 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions QuickRadar/ProductCategories.plist
Expand Up @@ -29,11 +29,11 @@
<string>com.apple.Java</string>
<string>com.apple.Jar</string>
</array>
<key>Mac App Store</key>
<key>OS X App Store</key>
<array>
<string>com.apple.appstore</string>
</array>
<key>Mac OS X</key>
<key>OS X</key>
<array>
<string>com.apple.finder</string>
<string>com.apple.dock</string>
Expand Down
2 changes: 1 addition & 1 deletion QuickRadar/QRAppListManager.h
Expand Up @@ -14,7 +14,7 @@

@interface QRAppListManager : NSObject

@property (nonatomic, readonly) NSMutableArray *appList;
@property (nonatomic, readonly) NSArray *appList;
@property (nonatomic, readonly) NSDictionary *categories;

+ (QRAppListManager *)sharedManager;
Expand Down
109 changes: 102 additions & 7 deletions QuickRadar/QRAppListManager.m
Expand Up @@ -13,8 +13,93 @@

#define kQRAppListApplePrefix @"com.apple"


@interface QRSystemFakeApplication : NSObject

-(id) initWithSysVersionDict: (NSDictionary*)inSysVersionDict;

@property (nonatomic,readwrite) NSDictionary* sysVersionDict;
@property (nonatomic, readonly) NSString *unlocalizedName;
@property (nonatomic, readonly) NSString *version;
@property (nonatomic, readonly) NSString *build;
@property (nonatomic, readonly) NSString *versionAndBuild;
@property (nonatomic, readonly) NSImage *icon;

@end


@implementation QRSystemFakeApplication

-(id) initWithSysVersionDict: (NSDictionary*)inSysVersionDict
{
self = [super init];
if( self )
self.sysVersionDict = inSysVersionDict;

return self;
}


-(NSString*) unlocalizedName
{
return [self.sysVersionDict objectForKey: @"ProductName"];
}

-(NSString*) name
{
return [self.sysVersionDict objectForKey: @"ProductName"];
}

-(NSString*) version
{
return [self.sysVersionDict objectForKey: @"ProductVersion"];
}

-(NSString*) build
{
return [self.sysVersionDict objectForKey: @"ProductBuildVersion"];
}

-(NSString*) versionAndBuild
{
return [NSString stringWithFormat: @"%@ (%@)", self.version, self.build];
}

-(NSImage*) icon
{
return [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode( 'macs' )];
}


-(BOOL) didCrashRecently
{
return NO;
}


- (NSString *)guessCategory
{
NSString *identifier = @"com.apple.dock"; // Dock is a part of us, so good guess.
NSDictionary *categories = [[QRAppListManager sharedManager] categories];
NSEnumerator *enumerator = [categories keyEnumerator];
NSString *key;
while ((key = [enumerator nextObject])) {
NSArray *bundlePrefixes = categories[key];
for (NSString *prefix in bundlePrefixes) {
if ([identifier hasPrefix:prefix]) {
return key;
}
}
}
return nil;
}

@end


@interface QRAppListManager ()
@property (nonatomic, readwrite) NSMutableArray *appList;
@property (nonatomic, readwrite) NSMutableArray *internalAppList;
@property (nonatomic, readwrite) QRSystemFakeApplication *systemFakeAppObject;
@end


Expand Down Expand Up @@ -46,11 +131,14 @@ - (id)init
name:NSWorkspaceDidActivateApplicationNotification object:nil];

// Try to load any cached list, otherwise start with empty list.
self.appList = [NSMutableArray arrayWithCapacity:15];
self.internalAppList = [NSMutableArray arrayWithCapacity:15];
NSArray *loadedList = [self loadList];
if (loadedList) {
[self.appList addObjectsFromArray:loadedList];
[self.internalAppList addObjectsFromArray:loadedList];
}

NSDictionary * sysVersionDict = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
self.systemFakeAppObject = [[QRSystemFakeApplication alloc] initWithSysVersionDict: sysVersionDict];
}
return self;
}
Expand All @@ -65,10 +153,10 @@ - (void)addApp:(QRCachedRunningApplication *)app {
NSInteger oldIndex = [self.appList indexOfObject:app];
userInfo[kQRAppListNotificationOldIndexKey] = @(oldIndex);
QRCachedRunningApplication *existingApp = self.appList[oldIndex];
[self.appList removeObjectAtIndex:oldIndex];
[self.appList insertObject:existingApp atIndex:0];
[self.internalAppList removeObjectAtIndex:oldIndex];
[self.internalAppList insertObject:existingApp atIndex:0];
} else {
[self.appList insertObject:app atIndex:0];
[self.internalAppList insertObject:app atIndex:0];
}
[[NSNotificationCenter defaultCenter] postNotificationName:kQRAppListUpdatesNotification object:self userInfo:userInfo];
}
Expand Down Expand Up @@ -101,7 +189,7 @@ - (NSString *)cacheFolder {

- (void)saveList {
NSString *plistPath = [[self cacheFolder] stringByAppendingPathComponent:@"AppList.plist"];
[NSKeyedArchiver archiveRootObject:self.appList toFile:plistPath];
[NSKeyedArchiver archiveRootObject:self.internalAppList toFile:plistPath];
}

- (NSArray *)loadList {
Expand All @@ -116,6 +204,13 @@ - (NSArray *)loadList {
return list;
}


- (NSArray*)appList {
NSMutableArray * apps = [[NSMutableArray alloc] initWithObjects: self.systemFakeAppObject, nil];
[apps addObjectsFromArray: self.internalAppList];
return apps;
}

#pragma mark -
#pragma mark Categories

Expand Down
2 changes: 1 addition & 1 deletion QuickRadar/QRAppListViewController.m
Expand Up @@ -90,7 +90,7 @@ - (void)reloadList {
}

- (id)listItemAtIndex:(NSInteger)index appsOnly:(BOOL)appsOnly {
NSMutableArray *appList = [QRAppListManager sharedManager].appList;
NSArray *appList = [QRAppListManager sharedManager].appList;
NSInteger appListCount = appList.count;
if (index > 0 && index <= appListCount)
return [QRAppListManager sharedManager].appList[index - 1];
Expand Down