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.

255 lines
10.0KB

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