You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
8.3KB

  1. #define kBundlePath @"/Library/Application Support/AVLockBundle.bundle"
  2. @interface SBOrientationLockManager
  3. +(SBOrientationLockManager *)sharedInstance;
  4. -(bool)isUserLocked;
  5. -(void)lock;
  6. -(void)unlock;
  7. -(void)myIsUserLocked;
  8. @end
  9. @interface AVButton : UIView
  10. @end
  11. @interface AVTransportControlsView : UIView
  12. -(void)deviceOrientationDidChange;
  13. @property (assign, nonatomic) AVButton *skipBackButton;
  14. @property (assign, nonatomic) AVButton *skipForwardButton;
  15. @property (assign, nonatomic) AVButton *standardPlayPauseButton;
  16. @end
  17. extern "C" CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
  18. static UIButton *button = nil;
  19. static NSString *myObserver=@"anObserver";
  20. static void toggle(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  21. if([[%c(SBOrientationLockManager) sharedInstance] isUserLocked]){
  22. [[%c(SBOrientationLockManager) sharedInstance] unlock];
  23. }else{
  24. [[%c(SBOrientationLockManager) sharedInstance] lock];
  25. }
  26. }
  27. static void lockButton(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  28. NSBundle *bundle = [[[NSBundle alloc] initWithPath:kBundlePath] autorelease];
  29. NSString *imagePath = [bundle pathForResource:@"Locked@3x" ofType:@"png"];
  30. UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
  31. [button setImage:img forState:UIControlStateNormal];
  32. [button setImage:img forState:UIControlStateHighlighted];
  33. [button setImage:img forState:UIControlStateSelected];
  34. }
  35. static void unlockButton(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  36. NSBundle *bundle = [[[NSBundle alloc] initWithPath:kBundlePath] autorelease];
  37. NSString *imagePath = [bundle pathForResource:@"Unlocked@3x" ofType:@"png"];
  38. UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
  39. [button setImage:img forState:UIControlStateNormal];
  40. [button setImage:img forState:UIControlStateHighlighted];
  41. [button setImage:img forState:UIControlStateSelected];
  42. }
  43. static void firstUpdate(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  44. [[%c(SBOrientationLockManager) sharedInstance] myIsUserLocked];
  45. }
  46. %hook SBOrientationLockManager
  47. -(SBOrientationLockManager*)init{
  48. self = %orig;
  49. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  50. (void*)myObserver,
  51. toggle,
  52. CFSTR("avlock.toggle"),
  53. NULL,
  54. CFNotificationSuspensionBehaviorDeliverImmediately);
  55. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  56. (void*)myObserver,
  57. firstUpdate,
  58. CFSTR("avlock.firstUpdate"),
  59. NULL,
  60. CFNotificationSuspensionBehaviorDeliverImmediately);
  61. return self;
  62. }
  63. %new
  64. -(void)myIsUserLocked{
  65. bool locked = [self isUserLocked];
  66. if(locked){
  67. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.lockButton"), (void*)myObserver, NULL, true);
  68. }else{
  69. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.unlockButton"), (void*)myObserver, NULL, true);
  70. }
  71. }
  72. -(void)unlock{
  73. %orig;
  74. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.unlockButton"), (void*)myObserver, NULL, true);
  75. }
  76. -(void)lock{
  77. %orig;
  78. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.lockButton"), (void*)myObserver, NULL, true);
  79. }
  80. %end
  81. %hook AVTransportControlsView
  82. int test = 30;
  83. // iOS 12
  84. -(AVTransportControlsView *)initWithFrame:(CGRect)frame styleSheet:(id)arg2 captureView:(id)arg3{
  85. AVTransportControlsView *origself = %orig(frame,arg2,arg3);
  86. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  87. (void*)myObserver,
  88. lockButton,
  89. CFSTR("avlock.lockButton"),
  90. NULL,
  91. CFNotificationSuspensionBehaviorDeliverImmediately);
  92. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  93. (void*)myObserver,
  94. unlockButton,
  95. CFSTR("avlock.unlockButton"),
  96. NULL,
  97. CFNotificationSuspensionBehaviorDeliverImmediately);
  98. button = [UIButton buttonWithType:UIButtonTypeCustom];
  99. [button addTarget:self action:@selector(orientationButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  100. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.firstUpdate"), (void*)myObserver, NULL, true);
  101. button.contentMode = UIViewContentModeScaleAspectFit;
  102. button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
  103. [self addSubview:button];
  104. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  105. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
  106. return origself;
  107. }
  108. // iOS 11
  109. -(AVTransportControlsView *)initWithFrame:(CGRect)frame{
  110. AVTransportControlsView *origself = %orig(frame);
  111. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  112. (void*)myObserver,
  113. lockButton,
  114. CFSTR("avlock.lockButton"),
  115. NULL,
  116. CFNotificationSuspensionBehaviorDeliverImmediately);
  117. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  118. (void*)myObserver,
  119. unlockButton,
  120. CFSTR("avlock.unlockButton"),
  121. NULL,
  122. CFNotificationSuspensionBehaviorDeliverImmediately);
  123. button = [UIButton buttonWithType:UIButtonTypeCustom];
  124. [button addTarget:self action:@selector(orientationButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  125. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.firstUpdate"), (void*)myObserver, NULL, true);
  126. button.contentMode = UIViewContentModeScaleAspectFit;
  127. button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
  128. [self addSubview:button];
  129. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  130. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
  131. return origself;
  132. }
  133. -(void)dealloc{
  134. %orig;
  135. CFNotificationCenterRemoveObserver ( CFNotificationCenterGetDarwinNotifyCenter(), (void*)myObserver, NULL, NULL);
  136. test = 30;
  137. }
  138. -(void)layoutSubviews{
  139. %orig;
  140. if(test > 1){
  141. [self deviceOrientationDidChange];
  142. test--;;
  143. }
  144. }
  145. %new
  146. -(void)deviceOrientationDidChange{
  147. double delayInSeconds = 0.13;
  148. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  149. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  150. UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  151. if (orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft){
  152. CGPoint point = self.standardPlayPauseButton.frame.origin;
  153. point.x = (self.skipForwardButton.frame.origin.x - 40);
  154. [self.standardPlayPauseButton setFrame:CGRectMake(point.x, point.y, self.standardPlayPauseButton.frame.size.width, self.standardPlayPauseButton.frame.size.height)];
  155. point = self.skipBackButton.frame.origin;
  156. point.x = (self.standardPlayPauseButton.frame.origin.x - 40);
  157. [self.skipBackButton setFrame:CGRectMake(point.x, point.y, self.skipBackButton.frame.size.width, self.skipBackButton.frame.size.height)];
  158. [button setFrame:CGRectMake(self.standardPlayPauseButton.frame.origin.x-93.5, self.standardPlayPauseButton.frame.origin.y, 46, 46)];
  159. }
  160. else if(orientation == UIInterfaceOrientationPortrait){
  161. button.frame = CGRectMake((self.skipBackButton.frame.origin.x - 62), self.skipBackButton.frame.origin.y, 46, 46);
  162. }
  163. });
  164. }
  165. %new
  166. -(void)orientationButtonPressed{
  167. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.toggle"), (void*)myObserver, NULL, true);
  168. }
  169. %end