Device battery indicators on your Lock Screen
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.

247 satır
6.0KB

  1. #include <CoreFoundation/CoreFoundation.h>
  2. #import <Foundation/Foundation.h>
  3. #include <stdio.h>
  4. #import <objc/runtime.h>
  5. #import <UIKit/UIKit.h>
  6. #import "KAIBattery.mm"
  7. @interface UIApplication (Kai)
  8. +(id)sharedApplication;
  9. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  10. @end
  11. @interface CSCoverSheetViewBase : UIView
  12. @property (nonatomic, strong) KAIBattery *battery;
  13. -(void)KaiUpdate;
  14. -(void)KaiInit;
  15. @end
  16. @interface SBCoverSheetPrimarySlidingViewController
  17. -(void)KaiUpdate;
  18. @end
  19. @interface CSMainPageView : UIView
  20. -(void)updateForPresentation:(id)arg1;
  21. @end
  22. @interface _CSSingleBatteryChargingView : UIView
  23. @end
  24. @interface NCNotificationListView : UIView
  25. @property (nonatomic, assign) BOOL hasKai;
  26. @property (nonatomic, assign) NSInteger previousKaiCount;
  27. @end
  28. BOOL setFrame = NO;
  29. NCNotificationListView *batteryWidgetController;
  30. KAIBattery *batteryWidget;
  31. CSCoverSheetViewBase *base;
  32. CGRect original;
  33. CGRect originalBattery;
  34. /*
  35. - (void)addObserver:(NSObject *)observer
  36. forKeyPath:(NSString *)keyPath
  37. options:(NSKeyValueObservingOptions)options
  38. context:(void *)context*/
  39. /*
  40. %hook BCBatterDeviceController
  41. +(id)sharedInstance {
  42. [%orig addObserver:self forKeyPath:@"sortedDevices" options:NSKeyValueObservingOptionNew context:nil];
  43. return %orig;
  44. }
  45. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  46. if ([keyPath isEqualToString:@"sortedDevices"]) {
  47. [[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.weather" suspended:NO];
  48. }
  49. }
  50. %end*/
  51. %hook CSMainPageView
  52. -(void)updateForPresentation:(id)arg1 {
  53. if(!setFrame) {
  54. if([self.subviews count] > 0) {
  55. CSCoverSheetViewBase *base = [self.subviews objectAtIndex:0];
  56. [base KaiInit];
  57. }
  58. }
  59. //[base KaiUpdate];
  60. }
  61. %end
  62. %hook SBCoverSheetPrimarySlidingViewController
  63. -(void)viewWillAppear:(BOOL)arg1 {
  64. %orig;
  65. [[NSNotificationCenter defaultCenter] addObserver:self
  66. selector:@selector(KaiUpdate)
  67. name:@"KaiInfoChanged"
  68. object:nil];
  69. //[self KaiUpdate];
  70. }
  71. %new
  72. -(void)KaiUpdate {
  73. [batteryWidget updateBattery];
  74. [base KaiUpdate];
  75. }
  76. %end
  77. %hook CSCoverSheetViewBase
  78. %property (nonatomic, strong) KAIBattery *battery;
  79. -(void)traitCollectionDidChange:(id)arg1 {
  80. %orig;
  81. [batteryWidget darkLightMode];
  82. }
  83. -(void)setNeedsLayout {
  84. %orig;
  85. //[self KaiUpdate];
  86. }
  87. %new
  88. -(void)KaiInit {
  89. if(!setFrame) {
  90. NCNotificationListView *scroller;
  91. if([self.subviews count] > 1) {
  92. UIView *temp = [self.subviews objectAtIndex:1];
  93. if([temp.subviews count] > 0) {
  94. scroller = [[temp.subviews objectAtIndex:0].subviews objectAtIndex:0];
  95. base = self;
  96. }
  97. }
  98. /*UIView *notiView;
  99. if([self.subviews count] > 0) {
  100. notiView = [self.subviews objectAtIndex:0];
  101. }*/
  102. original = scroller.frame;
  103. KAIBattery *battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, 0, self.frame.size.width - 16, self.frame.size.height)];
  104. originalBattery = battery.frame;
  105. [scroller addSubview:battery];
  106. setFrame = YES;
  107. batteryWidgetController = scroller;
  108. batteryWidget = battery;
  109. batteryWidgetController.previousKaiCount = 0;
  110. }
  111. [self KaiUpdate];
  112. [batteryWidget darkLightMode];
  113. }
  114. %new
  115. -(void)KaiUpdate {
  116. dispatch_async(dispatch_get_main_queue(), ^{
  117. [UIView animateWithDuration:0.3 animations:^{
  118. /*UIView *notiView;
  119. if([self.subviews count] > 0) {
  120. notiView = [self.subviews objectAtIndex:0];
  121. }*/
  122. batteryWidgetController.translatesAutoresizingMaskIntoConstraints = NO;
  123. /*for(UIView *view in batteryWidgetController.subviews) {
  124. view.bounds = CGRectMake(
  125. view.bounds.origin.x,
  126. view.bounds.origin.y - (batteryWidget.number * 85) + (batteryWidgetController.previousKaiCount * 85),
  127. view.bounds.size.width,
  128. view.bounds.size.height
  129. );
  130. }
  131. batteryWidgetController.previousKaiCount = batteryWidget.number;*/
  132. [batteryWidgetController.topAnchor constraintEqualToAnchor:batteryWidgetController.superview.topAnchor constant:(batteryWidget.number * 85)].active = YES;
  133. batteryWidget.frame = CGRectMake(
  134. originalBattery.origin.x,
  135. originalBattery.origin.y - (batteryWidget.number * 85),
  136. originalBattery.size.width,
  137. originalBattery.size.height
  138. );
  139. }];
  140. [batteryWidget darkLightMode];
  141. });
  142. }
  143. %end
  144. %hook NCNotificationListView
  145. %property (nonatomic, assign) BOOL hasKai;
  146. %property (nonatomic, assign) NSInteger previousKaiCount;
  147. //-(void)setBounds:(CGRect)arg1 {
  148. /*if(batteryWidgetController==self) {
  149. arg1 = (CGRectMake(
  150. original.origin.x,
  151. original.origin.y - (batteryWidget.number * 85),
  152. original.size.width,
  153. original.size.height
  154. ));
  155. batteryWidget.frame = CGRectMake(
  156. originalBattery.origin.x,
  157. originalBattery.origin.y - (batteryWidget.number * 85),
  158. originalBattery.size.width,
  159. originalBattery.size.height
  160. );
  161. [batteryWidget darkLightMode];
  162. }*/
  163. // %orig;
  164. //}
  165. %end
  166. %hook BCBatteryDevice
  167. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  168. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  169. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  170. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  171. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  172. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  173. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  174. return %orig;
  175. }
  176. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  177. dispatch_async(dispatch_get_main_queue(), ^{
  178. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  179. });
  180. }
  181. %end
  182. %hook _CSSingleBatteryChargingView
  183. -(void)initWithFrame:(CGRect)arg1 {
  184. %orig;
  185. [self removeFromSuperview];
  186. }
  187. -(CGFloat)desiredVisibilityDuration {
  188. return 0;
  189. }
  190. -(void)setBatteryVisible:(BOOL)arg1 {
  191. %orig(NO);
  192. }
  193. %end