Permalink
Browse files

use libdisplaystack & cleanup code

  • Loading branch information...
1 parent 6915292 commit 9be76e3d6a37e47b2e18e4dc9a1d2741818acfae @theiostream committed Feb 18, 2012
Showing with 18 additions and 60 deletions.
  1. +2 −3 Makefile
  2. +15 −56 Tweak.xm
  3. BIN am.theiostre.caffeine2_2.0-5_iphoneos-arm.deb
  4. +1 −1 control
View
@@ -1,12 +1,11 @@
GO_EASY_ON_ME=1
-THEOS_DEVICE_IP=192.168.1.104
-SDKVERSION = 4.3
+THEOS_DEVICE_IP=192.168.1.112
include theos/makefiles/common.mk
TWEAK_NAME = caffeine2
caffeine2_FILES = Tweak.xm
caffeine2_FRAMEWORKS = UIKit
-caffeine2_LDFLAGS = -lactivator
+caffeine2_LDFLAGS = -lactivator -ldisplaystack
include $(THEOS_MAKE_PATH)/tweak.mk
View
@@ -1,69 +1,25 @@
-#import <UIKit/UIKit.h>
-#import <objc/objc.h>
-#import <objc/runtime.h>
-#import <libactivator/libactivator.h>
+#import <libactivator.h>
+#import <libdisplaystack/DSDisplayController.h>
-#define SBWPreActivateDisplayStack [displayStacks objectAtIndex:0]
-#define SBWActiveDisplayStack [displayStacks objectAtIndex:1]
-#define SBWSuspendingDisplayStack [displayStacks objectAtIndex:2]
-#define SBWSuspendedEventOnlyDisplayStack [displayStacks objectAtIndex:3]
-
-static NSMutableArray *displayStacks;
-static NSDictionary *dict = [[[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/am.theiostre.caffeine2.plist"] autorelease];
static BOOL caffeineIsOn = NO;
-@interface SBApplication : NSObject {}
--(id)displayIdentifier;
-@end
-
-@interface Caffeine2 : NSObject<LAListener> {}
-@end
-
-//======= thx conradev + thezimm
-%hook SBDisplayStack
-
-- (id)init {
- if ((self = %orig)) {
- [displayStacks addObject:self];
- }
- return self;
-}
-
-- (void)dealloc {
- [displayStacks removeObject:self];
- %orig;
-}
-
-%end
-
%hook SpringBoard
-- (void)applicationDidFinishLaunching:(id)application {
- displayStacks = [[NSMutableArray arrayWithCapacity:4] retain];
- %orig;
-}
-//========
- (void)autoLock {
- %log;
-
- SBApplication *topApp = [SBWActiveDisplayStack topApplication];
+ NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/am.theiostre.caffeine2.plist"];
+ SBApplication *topApp = [[[DSDisplayController sharedInstance] activeStack] topApplication];
if (topApp) {
BOOL cofa = [[dict objectForKey:[@"CaffeineIsOn-" stringByAppendingString:[topApp displayIdentifier]]] boolValue];
-
- if (!cofa) {
- if (!caffeineIsOn) %orig;
- }
- }
-
- // springboard crashes if I don't include this. It seems to return nil on -(id)topApplication;
- else {
- if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.springboard"])
- if (!caffeineIsOn) %orig;
+ if (cofa) return;
}
+ if (!caffeineIsOn) %orig;
}
%end
+@interface Caffeine2 : NSObject <LAListener>
+@end
+
@implementation Caffeine2
- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event {
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Caffeine" message:@"" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
@@ -77,8 +33,11 @@ static BOOL caffeineIsOn = NO;
[theAlert release];
}
-+(void)load
-{
++ (void)load {
[[LAActivator sharedInstance] registerListener:[self new] forName:@"am.theiostre.ios-caffeine"];
}
-@end
+@end
+
+%ctor {
+ dlopen("/Library/MobileSubstrate/DynamicLibraries/DisplayStack.dylib", RTLD_LAZY);
+}
Binary file not shown.
View
@@ -1,6 +1,6 @@
Package: am.theiostre.caffeine2
Name: caffeine2
-Depends: mobilesubstrate
+Depends: mobilesubstrate, com.zimm.libdisplaystack, applist
Version: 2.0
Architecture: iphoneos-arm
Description: An awesome MobileSubstrate tweak!

0 comments on commit 9be76e3

Please sign in to comment.