1
0
mirror of https://github.com/gilshahar7/AVLock.git synced 2025-07-01 17:56:46 +00:00
Files
AVLock/Tweak.xm
2018-03-25 18:37:33 +03:00

54 lines
1.4 KiB
Plaintext

#define kBundlePath @"/Library/MobileSubstrate/DynamicLibraries/AVLockBundle.bundle"
@interface SBOrientationLockManager
+(SBOrientationLockManager *)sharedInstance;
-(bool)isUserLocked;
-(void)lock;
-(void)unlock;
@end
@interface AVTransportControlsView
-(void)addSubview:(id)arg1;
@property CGRect frame;
@end
static bool firstrun = true;
%hook AVTransportControlsView
-(void)layoutSubviews{
%orig;
if(firstrun){
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(orientationButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
NSBundle *bundle = [[NSBundle alloc] initWithPath:kBundlePath];
NSString *imagePath = [bundle pathForResource:@"Test" ofType:@"png"];
UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
[button setImage:img forState:UIControlStateNormal];
[button setImage:img forState:UIControlStateHighlighted];
[button setImage:img forState:UIControlStateSelected];
button.contentMode = UIViewContentModeScaleToFill;
button.frame = CGRectMake(0, 0, img.size.width, img.size.height);
[self addSubview:button];
firstrun = false;
}
}
-(void)dealloc{
%orig;
firstrun = true;
}
%new
-(void)orientationButtonPressed{
if([[%c(SBOrientationLockManager) sharedInstance] isUserLocked]){
[[%c(SBOrientationLockManager) sharedInstance] unlock];
}else{
[[%c(SBOrientationLockManager) sharedInstance] lock];
}
}
%end