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.

Tweak.xm 10.0KB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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