forked from rpetrich/AppList
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7790fbe
Showing
13 changed files
with
681 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
._* | ||
*.deb | ||
.debmake | ||
_ | ||
obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "framework"] | ||
path = framework | ||
url = git://github.com/rpetrich/theos.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <CoreGraphics/CoreGraphics.h> | ||
|
||
enum { | ||
ALApplicationIconSizeSmall = 29, | ||
ALApplicationIconSizeLarge = 59 | ||
}; | ||
typedef NSUInteger ALApplicationIconSize; | ||
|
||
@class CPDistributedMessagingCenter; | ||
|
||
@interface ALApplicationList : NSObject { | ||
@private | ||
CPDistributedMessagingCenter *messagingCenter; | ||
} | ||
+ (id)sharedApplicationList; | ||
|
||
@property (nonatomic, readonly) NSDictionary *applications; | ||
|
||
@property (nonatomic, readonly) NSDictionary *userApplications; | ||
@property (nonatomic, readonly) NSDictionary *systemApplications; | ||
|
||
- (CGImageRef)copyIconOfSize:(ALApplicationIconSize)iconSize forDisplayIdentifier:(NSString *)displayIdentifier; | ||
- (UIImage *)iconOfSize:(ALApplicationIconSize)iconSize forDisplayIdentifier:(NSString *)displayIdentifier; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
#import "ALApplicationList.h" | ||
|
||
#import <ImageIO/ImageIO.h> | ||
#import <UIKit/UIKit.h> | ||
#import <SpringBoard/SpringBoard.h> | ||
#import <CaptainHook/CaptainHook.h> | ||
#import <AppSupport/AppSupport.h> | ||
|
||
@interface ALApplicationList () | ||
|
||
@property (nonatomic, readonly) CPDistributedMessagingCenter *messagingCenter; | ||
|
||
@end | ||
|
||
@interface ALApplicationListImpl : ALApplicationList { | ||
} | ||
|
||
@end | ||
|
||
static ALApplicationList *sharedApplicationList; | ||
|
||
@implementation ALApplicationList | ||
|
||
+ (id)sharedApplicationList | ||
{ | ||
return sharedApplicationList; | ||
} | ||
|
||
- (id)init | ||
{ | ||
if ((self = [super init])) { | ||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||
messagingCenter = [[CPDistributedMessagingCenter centerNamed:@"applist.springboardCenter"] retain]; | ||
[pool drain]; | ||
} | ||
return self; | ||
} | ||
|
||
@synthesize messagingCenter; | ||
|
||
- (void)dealloc | ||
{ | ||
[messagingCenter release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (NSDictionary *)applications | ||
{ | ||
return [messagingCenter sendMessageAndReceiveReplyName:@"applications" userInfo:nil]; | ||
} | ||
|
||
- (NSDictionary *)userApplications | ||
{ | ||
return [messagingCenter sendMessageAndReceiveReplyName:@"userApplications" userInfo:nil]; | ||
} | ||
|
||
- (NSDictionary *)systemApplications | ||
{ | ||
return [messagingCenter sendMessageAndReceiveReplyName:@"systemApplications" userInfo:nil]; | ||
} | ||
|
||
- (CGImageRef)copyIconOfSize:(ALApplicationIconSize)iconSize forDisplayIdentifier:(NSString *)displayIdentifier | ||
{ | ||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:iconSize], @"iconSize", displayIdentifier, @"displayIdentifier", nil]; | ||
NSDictionary *serialized = [messagingCenter sendMessageAndReceiveReplyName:@"_remoteGetIconForMessage:userInfo:" userInfo:userInfo]; | ||
NSData *data = [serialized objectForKey:@"result"]; | ||
if (!data) | ||
return NULL; | ||
CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)data, NULL); | ||
CGImageRef result = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); | ||
CFRelease(imageSource); | ||
return result; | ||
} | ||
|
||
- (UIImage *)iconOfSize:(ALApplicationIconSize)iconSize forDisplayIdentifier:(NSString *)displayIdentifier | ||
{ | ||
CGImageRef image = [self copyIconOfSize:iconSize forDisplayIdentifier:displayIdentifier]; | ||
if (!image) | ||
return nil; | ||
UIImage *result = [UIImage imageWithCGImage:image]; | ||
CGImageRelease(image); | ||
return result; | ||
} | ||
|
||
@end | ||
|
||
CHDeclareClass(SBApplicationController); | ||
CHDeclareClass(SBIconModel); | ||
|
||
@interface SBIcon () | ||
|
||
- (UIImage *)getIconImage:(NSInteger)sizeIndex; | ||
|
||
@end | ||
|
||
@implementation ALApplicationListImpl | ||
|
||
- (id)init | ||
{ | ||
if ((self = [super init])) { | ||
CPDistributedMessagingCenter *center = [self messagingCenter]; | ||
[center runServerOnCurrentThread]; | ||
[center registerForMessageName:@"applications" target:self selector:@selector(applications)]; | ||
[center registerForMessageName:@"userApplications" target:self selector:@selector(userApplications)]; | ||
[center registerForMessageName:@"systemApplications" target:self selector:@selector(systemApplications)]; | ||
[center registerForMessageName:@"_remoteGetIconForMessage:userInfo:" target:self selector:@selector(_remoteGetIconForMessage:userInfo:)]; | ||
} | ||
return self; | ||
} | ||
|
||
- (NSDictionary *)applications | ||
{ | ||
NSMutableDictionary *result = [NSMutableDictionary dictionary]; | ||
for (SBApplication *app in [CHSharedInstance(SBApplicationController) allApplications]) | ||
[result setObject:[app displayName] forKey:[app displayIdentifier]]; | ||
return result; | ||
} | ||
|
||
- (NSDictionary *)userApplications | ||
{ | ||
NSMutableDictionary *result = [NSMutableDictionary dictionary]; | ||
for (SBApplication *app in [CHSharedInstance(SBApplicationController) allApplications]) | ||
if (![app isSystemApplication]) | ||
[result setObject:[app displayName] forKey:[app displayIdentifier]]; | ||
return result; | ||
} | ||
|
||
- (NSDictionary *)systemApplications | ||
{ | ||
NSMutableDictionary *result = [NSMutableDictionary dictionary]; | ||
for (SBApplication *app in [CHSharedInstance(SBApplicationController) allApplications]) | ||
if ([app isSystemApplication]) | ||
[result setObject:[app displayName] forKey:[app displayIdentifier]]; | ||
return result; | ||
} | ||
|
||
- (NSDictionary *)_remoteGetIconForMessage:(NSString *)message userInfo:(NSDictionary *)userInfo | ||
{ | ||
CGImageRef image = [self copyIconOfSize:[[userInfo objectForKey:@"iconSize"] unsignedIntegerValue] forDisplayIdentifier:[userInfo objectForKey:@"displayIdentifier"]]; | ||
if (!image) | ||
return [NSDictionary dictionary]; | ||
NSMutableData *result = [NSMutableData data]; | ||
CGImageDestinationRef dest = CGImageDestinationCreateWithData((CFMutableDataRef)result, CFSTR("public.png"), 1, NULL); | ||
CGImageDestinationAddImage(dest, image, NULL); | ||
CGImageRelease(image); | ||
CGImageDestinationFinalize(dest); | ||
CFRelease(dest); | ||
return [NSDictionary dictionaryWithObject:result forKey:@"result"]; | ||
} | ||
|
||
- (CGImageRef)copyIconOfSize:(ALApplicationIconSize)iconSize forDisplayIdentifier:(NSString *)displayIdentifier | ||
{ | ||
SBIcon *icon = [CHSharedInstance(SBIconModel) iconForDisplayIdentifier:displayIdentifier]; | ||
BOOL getIconImage = [icon respondsToSelector:@selector(getIconImage:)]; | ||
SBApplication *app = [CHSharedInstance(SBApplicationController) applicationWithDisplayIdentifier:displayIdentifier]; | ||
UIImage *image; | ||
if (iconSize <= ALApplicationIconSizeSmall) { | ||
image = getIconImage ? [icon getIconImage:0] : [icon smallIcon]; | ||
if (image) | ||
goto finish; | ||
image = [UIImage imageWithContentsOfFile:[app pathForSmallIcon]]; | ||
if (image) | ||
goto finish; | ||
} | ||
image = getIconImage ? [icon getIconImage:1] : [icon icon]; | ||
if (image) | ||
goto finish; | ||
image = [UIImage imageWithContentsOfFile:[app pathForIcon]]; | ||
finish: | ||
return CGImageRetain([image CGImage]); | ||
} | ||
|
||
@end | ||
|
||
|
||
CHConstructor { | ||
CHAutoreleasePoolForScope(); | ||
CHLoadLateClass(SBIconModel); | ||
CHLoadLateClass(SBApplicationController); | ||
if (CHClass(SBApplicationController)) | ||
sharedApplicationList = [[ALApplicationListImpl alloc] init]; | ||
else | ||
sharedApplicationList = [[ALApplicationList alloc] init]; | ||
} |
Oops, something went wrong.