From: Jay Freeman (saurik) Date: Sun, 8 Nov 2009 05:27:55 +0000 (+0000) Subject: Checkpoint for Welcome. X-Git-Tag: v0.9.4000~55 X-Git-Url: https://git.saurik.com/cydget.git/commitdiff_plain/3a0081b3c433c6cc24d8e6133adf6822ce503bfa Checkpoint for Welcome. --- diff --git a/AwayView.cydget/Info.plist b/AwayView.cydget/Info.plist new file mode 100644 index 0000000..41e0365 --- /dev/null +++ b/AwayView.cydget/Info.plist @@ -0,0 +1 @@ +Tagline = "represents the lack of any cydget display"; diff --git a/CydgetCentral.plist b/CydgetCentral.plist index ba2e841..d4cead1 100644 --- a/CydgetCentral.plist +++ b/CydgetCentral.plist @@ -1,3 +1,4 @@ +Tagline = "particularly lame example for you to remove"; Plugin = "WebCycriptLockScreen"; Configuration = { diff --git a/CydgetSettings.bundle/Cydget.plist b/CydgetSettings.bundle/Cydget.plist new file mode 100644 index 0000000..9fb3ceb --- /dev/null +++ b/CydgetSettings.bundle/Cydget.plist @@ -0,0 +1,10 @@ +items = ({ + cell = PSGroupCell; +}, { + cell = PSLinkCell; + detail = CydgetOrderController; + icon = LockCydgets.png; + label = "Lock Cydget Order"; +}); + +title = Cydget; diff --git a/CydgetSettings.bundle/Info.plist b/CydgetSettings.bundle/Info.plist new file mode 100644 index 0000000..334c292 --- /dev/null +++ b/CydgetSettings.bundle/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + CydgetSettings + CFBundleIdentifier + com.saurik.winterboard.settings + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 0.9 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + DTPlatformName + iphoneos + MinimumOSVersion + 3.0 + NSPrincipalClass + CydgetSettingsController + + diff --git a/CydgetSettings.bundle/LockCydgets.png b/CydgetSettings.bundle/LockCydgets.png new file mode 100644 index 0000000..ab4a13c Binary files /dev/null and b/CydgetSettings.bundle/LockCydgets.png differ diff --git a/CydgetSettings.mm b/CydgetSettings.mm index 5d79fd9..dbe5ab7 100644 --- a/CydgetSettings.mm +++ b/CydgetSettings.mm @@ -1,4 +1,4 @@ -/* WinterBoard - Theme Manager for the iPhone +/* CydgetScript - open-source IntelliDial replacement * Copyright (C) 2009 Jay Freeman (saurik) */ @@ -53,7 +53,7 @@ static NSMutableDictionary *_settings; static NSString *_plist; /* Theme Settings Controller {{{ */ -@interface WBSThemesController: PSViewController { +@interface CydgetOrderController: PSViewController { UITableView *_tableView; NSMutableArray *_themes; } @@ -79,51 +79,35 @@ static NSString *_plist; @end -@implementation WBSThemesController +@implementation CydgetOrderController @synthesize themes = _themes; + (void) load { NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); checkImage = [_UIImageWithName(@"UIPreferencesBlueCheck.png") retain]; - uncheckedImage = [[UIImage imageWithContentsOfFile:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle/SearchResultsCheckmarkClear.png"] retain]; + uncheckedImage = [[UIImage imageWithContentsOfFile:@"/System/Library/PreferenceBundles/CydgetSettings.bundle/SearchResultsCheckmarkClear.png"] retain]; [pool release]; } - (id) initForContentSize:(CGSize)size { if ((self = [super initForContentSize:size]) != nil) { - self.themes = [_settings objectForKey:@"Themes"]; + self.themes = [_settings objectForKey:@"LockCydgets"]; if (!_themes) { - if (NSString *theme = [_settings objectForKey:@"Theme"]) { - self.themes = [NSMutableArray arrayWithObject: - [NSMutableDictionary dictionaryWithObjectsAndKeys: - theme, @"Name", - [NSNumber numberWithBool:YES], @"Active", nil]]; - [_settings removeObjectForKey:@"Theme"]; - } - if (!_themes) - self.themes = [NSMutableArray array]; - [_settings setObject:_themes forKey:@"Themes"]; - } - - NSMutableArray *themesOnDisk([NSMutableArray array]); + self.themes = [NSMutableArray arrayWithObjects:[NSMutableDictionary dictionaryWithObjectsAndKeys: + @"AwayView", @"Name", [NSNumber numberWithBool:YES], @"Active", nil + ], [NSMutableDictionary dictionaryWithObjectsAndKeys: + @"CydgetCentral", @"Name", [NSNumber numberWithBool:YES], @"Active", nil + ], nil]; - [themesOnDisk - addObjectsFromArray:[[NSFileManager defaultManager] - contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL] - ]; - - [themesOnDisk addObjectsFromArray:[[NSFileManager defaultManager] - contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()] - error:NULL - ]]; - - for (int i = 0, count = [themesOnDisk count]; i < count; i++) { - NSString *theme = [themesOnDisk objectAtIndex:i]; - if ([theme hasSuffix:@".theme"]) - [themesOnDisk replaceObjectAtIndex:i withObject:[theme stringByDeletingPathExtension]]; + [_settings setObject:_themes forKey:@"LockCydgets"]; } + NSMutableArray *themesOnDisk([NSMutableArray arrayWithCapacity:4]); + for (NSString *theme in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/System/Library/LockCydgets" error:NULL]) + if ([theme hasSuffix:@".cydget"]) + [themesOnDisk addObject:[theme stringByDeletingPathExtension]]; + NSMutableSet *themesSet([NSMutableSet set]); for (int i = 0, count = [_themes count]; i < count; i++) { @@ -155,7 +139,7 @@ static NSString *_plist; [_tableView setDelegate:self]; [_tableView setEditing:YES]; [_tableView setAllowsSelectionDuringEditing:YES]; - [self showLeftButton:@"WinterBoard" withStyle:1 rightButton:nil withStyle:0]; + [self showLeftButton:@"Cydget" withStyle:1 rightButton:nil withStyle:0]; } return self; } @@ -167,7 +151,7 @@ static NSString *_plist; } - (id) navigationTitle { - return @"Themes"; + return @"Lock Cydgets"; } - (id) view { @@ -244,7 +228,7 @@ static NSString *_plist; @end /* }}} */ -@interface WBSettingsController: PSListController { +@interface CydgetSettingsController: PSListController { } - (id) initForContentSize:(CGSize)size; @@ -261,11 +245,11 @@ static NSString *_plist; @end -@implementation WBSettingsController +@implementation CydgetSettingsController - (id) initForContentSize:(CGSize)size { if ((self = [super initForContentSize:size]) != nil) { - _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain]; + _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Cydget.plist", NSHomeDirectory()] retain]; _settings = [([NSMutableDictionary dictionaryWithContentsOfFile:_plist] ?: [NSMutableDictionary dictionary]) retain]; } return self; } @@ -322,7 +306,7 @@ static NSString *_plist; - (id) specifiers { if (!_specifiers) - _specifiers = [[self loadSpecifiersFromPlistName:@"WinterBoard" target:self] retain]; + _specifiers = [[self loadSpecifiersFromPlistName:@"Cydget" target:self] retain]; return _specifiers; } @@ -332,7 +316,7 @@ static NSString *_plist; } - (NSString *) title { - return @"WinterBoard"; + return @"Cydget"; } - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec { diff --git a/Icon-Small.png b/Icon-Small.png new file mode 100644 index 0000000..2c69f11 Binary files /dev/null and b/Icon-Small.png differ diff --git a/Index.html b/Index.html index 33f98a5..5757782 100644 --- a/Index.html +++ b/Index.html @@ -41,31 +41,34 @@ } #lcd h2 { - font-family: "LockClock-Light"; + font-family: "Helvetica"; font-size: 17px; - left: 2px; position: relative; text-align: center; text-shadow: -0.5px -1px 1px black; top: -16px; } -
-

+ +
diff --git a/Index.js b/Index.js index 4d07295..315a3b1 100644 --- a/Index.js +++ b/Index.js @@ -1,3 +1,3 @@ -with (Cycript.runtime) { +with (Cycript.all) { document.write('

[' + malloc + ']

'); } diff --git a/LockScreen.mm b/LockScreen.mm index 76c6cdc..f1963e7 100644 --- a/LockScreen.mm +++ b/LockScreen.mm @@ -717,9 +717,82 @@ MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::Parse return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, data, line, message); }*/ +/* Cydget:// Protocol {{{ */ +@interface CydgetURLProtocol : NSURLProtocol { +} + +@end + +@implementation CydgetURLProtocol + ++ (BOOL) canInitWithRequest:(NSURLRequest *)request { + NSURL *url([request URL]); + if (url == nil) + return NO; + NSString *scheme([[url scheme] lowercaseString]); + if (scheme == nil || ![scheme isEqualToString:@"cydget"]) + return NO; + return YES; +} + ++ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request { + return request; +} + +- (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request { + id client([self client]); + if (icon == nil) + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]]; + else { + NSData *data(UIImagePNGRepresentation(icon)); + + NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]); + [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; + [client URLProtocol:self didLoadData:data]; + [client URLProtocolDidFinishLoading:self]; + } +} + +- (void) startLoading { + id client([self client]); + NSURLRequest *request([self request]); + + NSURL *url([request URL]); + NSString *href([url absoluteString]); + + NSString *path([href substringFromIndex:9]); + NSRange slash([path rangeOfString:@"/"]); + + NSString *command; + if (slash.location == NSNotFound) { + command = path; + path = nil; + } else { + command = [path substringToIndex:slash.location]; + path = [path substringFromIndex:(slash.location + 1)]; + } + + if ([command isEqualToString:@"_UIImageWithName"]) { + if (path == nil) + goto fail; + path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + UIImage *icon(_UIImageWithName(path)); + [self _returnPNGWithImage:icon forRequest:request]; + } else fail: { + [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]]; + } +} + +- (void) stopLoading { +} + +@end +/* }}} */ + @implementation WebCycriptLockScreenController + (void) initialize { + [NSURLProtocol registerClass:[CydgetURLProtocol class]]; //MSHookFunction(&_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)); if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL)) CYSetupContext = reinterpret_cast(dlsym(handle, "CYSetupContext")); diff --git a/Tweak.mm b/Tweak.mm index 6702a7f..cd25dfd 100644 --- a/Tweak.mm +++ b/Tweak.mm @@ -43,6 +43,7 @@ #import #import +#import MSClassHook(SpringBoard) MSClassHook(SBAwayController) @@ -56,8 +57,9 @@ MSClassHook(SBAwayView) static bool menu_; static unsigned lock_; +static _H settings_; static _H cydgets_; -static size_t active_ = _not(size_t); +static size_t active_; @interface CydgetController : NSObject { } @@ -69,7 +71,7 @@ static size_t active_ = _not(size_t); @implementation CydgetController + (NSDictionary *) currentConfiguration { - return active_ == _not(size_t) ? nil : [[cydgets_ objectAtIndex:active_] objectForKey:@"Configuration"]; + return [[cydgets_ objectAtIndex:active_] objectForKey:@"Configuration"]; } @end @@ -82,160 +84,90 @@ static size_t active_ = _not(size_t); @implementation NSDictionary (Cydgets) - (void) enableCydget:(SBAwayController *)away { - [away enableLockScreenBundleWithName:[self objectForKey:@"Plugin"]]; + if (NSString *plugin = [self objectForKey:@"Plugin"]) + [away enableLockScreenBundleWithName:plugin]; } - (void) disableCydget:(SBAwayController *)away { - [away disableLockScreenBundleWithName:[self objectForKey:@"Plugin"]]; + if (NSString *plugin = [self objectForKey:@"Plugin"]) + [away disableLockScreenBundleWithName:plugin]; } @end -MSHook(BOOL, SBAwayController$handleMenuButtonTap, SBAwayController *self, SEL sel) { +MSInstanceMessageHook0(BOOL, SBAwayController, handleMenuButtonTap) { unsigned lock(lock_); - if (!_SBAwayController$handleMenuButtonTap(self, sel) && lock != 2) { - if (active_ != _not(size_t)) - [[cydgets_ objectAtIndex:active_] disableCydget:self]; - - size_t count([cydgets_ count]); - if ((++active_ %= count + 1) == count) - active_ = _not(size_t); - else - [[cydgets_ objectAtIndex:active_] enableCydget:self]; + if (!MSOldCall() && lock != 2) { + [[cydgets_ objectAtIndex:active_] disableCydget:self]; + active_ = (active_ + 1) % [cydgets_ count]; + [[cydgets_ objectAtIndex:active_] enableCydget:self]; } return YES; } -MSHook(void, SBAwayController$_undimScreen, SBAwayController *self, SEL sel) { +MSInstanceMessageHook0(void, SBAwayController, _undimScreen) { if (lock_ == 1) lock_ = 2; - _SBAwayController$_undimScreen(self, sel); + [[cydgets_ objectAtIndex:active_] enableCydget:[$SBAwayController sharedAwayController]]; + MSOldCall(); } -MSHook(void, SBAwayController$undimScreen, SBAwayController *self, SEL sel) { +MSInstanceMessageHook0(void, SBAwayController, undimScreen) { lock_ = menu_ ? 1 : 0; - _SBAwayController$undimScreen(self, sel); + MSOldCall(); } static void Deactivate_(SBAwayController *self) { - if (active_ != _not(size_t)) { - [[cydgets_ objectAtIndex:active_] disableCydget:self]; - active_ = _not(size_t); - } + [[cydgets_ objectAtIndex:active_] disableCydget:self]; + active_ = 0; } -MSHook(void, SBAwayController$finishedDimmingScreen, SBAwayController *self, SEL sel) { +MSInstanceMessageHook0(void, SBAwayController, finishedDimmingScreen) { Deactivate_(self); - _SBAwayController$finishedDimmingScreen(self, sel); + MSOldCall(); } -MSHook(void, SpringBoard$menuButtonUp$, UIView *self, SEL sel, GSEventRef event) { +MSInstanceMessageHook1(void, SpringBoard, menuButtonUp, GSEventRef, event) { menu_ = true; - _SpringBoard$menuButtonUp$(self, sel, event); + MSOldCall(event); menu_ = false; } -MSHook(void, SBAwayView$addGestureRecognizer$, UIView *self, SEL sel, id gr) { - //_SBAwayView$addGestureRecognizer$(self, sel, gr); -} - -MSInstanceMessageHook1(void, SBAwayController, _finishedUnlockAttemptWithStatus, BOOL, status) { - if (status) - Deactivate_(self); - MSOldCall(status); -} - -/* Cydget:// Protocol {{{ */ -@interface CydgetURLProtocol : NSURLProtocol { -} - -@end - -@implementation CydgetURLProtocol - -+ (BOOL) canInitWithRequest:(NSURLRequest *)request { - NSURL *url([request URL]); - if (url == nil) - return NO; - NSString *scheme([[url scheme] lowercaseString]); - if (scheme == nil || ![scheme isEqualToString:@"cydget"]) - return NO; - return YES; -} - -+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request { - return request; -} - -- (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request { - id client([self client]); - if (icon == nil) - [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]]; - else { - NSData *data(UIImagePNGRepresentation(icon)); - - NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]); - [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; - [client URLProtocol:self didLoadData:data]; - [client URLProtocolDidFinishLoading:self]; - } +MSInstanceMessageHook1(void, SBAwayView, addGestureRecognizer, id, recognizer) { + // MSOldCall(recognizer); } -- (void) startLoading { - id client([self client]); - NSURLRequest *request([self request]); - - NSURL *url([request URL]); - NSString *href([url absoluteString]); +#define Cydgets_ @"/System/Library/LockCydgets" - NSString *path([href substringFromIndex:9]); - NSRange slash([path rangeOfString:@"/"]); +static void CydgetSetup() { + NSString *plist([NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Cydget.plist", NSHomeDirectory()]); + settings_ = [NSMutableDictionary dictionaryWithContentsOfFile:plist] ?: [NSMutableDictionary dictionary]; - NSString *command; - if (slash.location == NSNotFound) { - command = path; - path = nil; - } else { - command = [path substringToIndex:slash.location]; - path = [path substringFromIndex:(slash.location + 1)]; - } + NSArray *cydgets([settings_ objectForKey:@"LockCydgets"] ?: [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys: + @"AwayView", @"Name", [NSNumber numberWithBool:YES], @"Active", nil + ], [NSDictionary dictionaryWithObjectsAndKeys: + @"CydgetCentral", @"Name", [NSNumber numberWithBool:YES], @"Active", nil + ], nil]); - if ([command isEqualToString:@"_UIImageWithName"]) { - if (path == nil) - goto fail; - path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - UIImage *icon(_UIImageWithName(path)); - [self _returnPNGWithImage:icon forRequest:request]; - } else fail: { - [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]]; - } + cydgets_ = [NSMutableArray arrayWithCapacity:4]; + for (NSDictionary *cydget in cydgets) + if ([[cydget objectForKey:@"Active"] boolValue]) + if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.cydget/Info.plist", Cydgets_, [cydget objectForKey:@"Name"]]]) + [cydgets_ addObject:info]; } -- (void) stopLoading { +// XXX: this could happen while it is unlocked +MSInstanceMessageHook1(id, SBAwayView, initWithFrame, CGRect, frame) { + self = MSOldCall(frame); + CydgetSetup(); + [[cydgets_ objectAtIndex:active_] enableCydget:[$SBAwayController sharedAwayController]]; + return self; } -@end -/* }}} */ - -#define Cydgets_ @"/System/Library/LockCydgets" - -MSInitialize { _pooled - [NSURLProtocol registerClass:[CydgetURLProtocol class]]; - - cydgets_ = [NSMutableArray arrayWithCapacity:4]; - - for (NSString *folder in [[NSFileManager defaultManager] directoryContentsAtPath:Cydgets_]) - if ([folder hasSuffix:@".cydget"]) - [cydgets_ addObject:[NSDictionary dictionaryWithContentsOfFile:[[Cydgets_ stringByAppendingPathComponent:folder] stringByAppendingPathComponent:@"Info.plist"]]]; - - MSHookMessage1(SpringBoard, menuButtonUp); - - MSHookMessage0(SBAwayController, handleMenuButtonTap); - MSHookMessage0(SBAwayController, _undimScreen); - MSHookMessage0(SBAwayController, undimScreen); - MSHookMessage0(SBAwayController, finishedDimmingScreen); - - MSHookMessage1(SBAwayView, addGestureRecognizer); +MSInstanceMessageHook1(void, SBAwayController, _finishedUnlockAttemptWithStatus, BOOL, status) { + if (status) + Deactivate_(self); + MSOldCall(status); } diff --git a/control b/control index 159e3be..e100ed2 100644 --- a/control +++ b/control @@ -3,7 +3,7 @@ Priority: optional Section: Development Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.3076-1 +Version: 0.9.3079-1 Description: framework for managing lock screen plugins Name: Cydget Depends: mobilesubstrate (>= 0.9.2587-1), cycript (>= 0.9.252) diff --git a/makefile b/makefile index f88b187..2108060 100644 --- a/makefile +++ b/makefile @@ -22,12 +22,13 @@ extra: mkdir -p package/System/Library/LockCydgets/CydgetCentral.cydget cp -a Index.{html,js} package/System/Library/LockCydgets/CydgetCentral.cydget cp -a CydgetCentral.plist package/System/Library/LockCydgets/CydgetCentral.cydget/Info.plist + svn export AwayView.cydget package/System/Library/LockCydgets/AwayView.cydget mkdir -p package/System/Library/SpringBoardPlugins/WebCycriptLockScreen.bundle cp -a Info.plist package/System/Library/SpringBoardPlugins/WebCycriptLockScreen.bundle cp -a WebCycriptLockScreen package/System/Library/SpringBoardPlugins/WebCycriptLockScreen.bundle mkdir -p package/Library/PreferenceLoader/Preferences mkdir -p package/System/Library/PreferenceBundles cp -a CydgetSettings.plist package/Library/PreferenceLoader/Preferences - cp -a CydgetSettings.bundle package/System/Library/PreferenceBundles + svn export CydgetSettings.bundle package/System/Library/PreferenceBundles/CydgetSettings.bundle cp -a Icon-Small.png package/System/Library/PreferenceBundles/CydgetSettings.bundle/icon.png cp -a SearchResultsCheckmarkClear.png CydgetSettings package/System/Library/PreferenceBundles/CydgetSettings.bundle