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.

248 lines
6.1KB

  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. batteryWidgetController.translatesAutoresizingMaskIntoConstraints = NO;*/
  134. batteryWidget.frame = CGRectMake(
  135. originalBattery.origin.x,
  136. originalBattery.origin.y - (batteryWidget.number * 85),
  137. originalBattery.size.width,
  138. originalBattery.size.height
  139. );
  140. }];
  141. [batteryWidget darkLightMode];
  142. });
  143. }
  144. %end
  145. %hook NCNotificationListView
  146. %property (nonatomic, assign) BOOL hasKai;
  147. %property (nonatomic, assign) NSInteger previousKaiCount;
  148. //-(void)setBounds:(CGRect)arg1 {
  149. /*if(batteryWidgetController==self) {
  150. arg1 = (CGRectMake(
  151. original.origin.x,
  152. original.origin.y - (batteryWidget.number * 85),
  153. original.size.width,
  154. original.size.height
  155. ));
  156. batteryWidget.frame = CGRectMake(
  157. originalBattery.origin.x,
  158. originalBattery.origin.y - (batteryWidget.number * 85),
  159. originalBattery.size.width,
  160. originalBattery.size.height
  161. );
  162. [batteryWidget darkLightMode];
  163. }*/
  164. // %orig;
  165. //}
  166. %end
  167. %hook BCBatteryDevice
  168. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  169. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  170. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  171. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  172. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  173. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  174. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  175. return %orig;
  176. }
  177. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  178. dispatch_async(dispatch_get_main_queue(), ^{
  179. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  180. });
  181. }
  182. %end
  183. %hook _CSSingleBatteryChargingView
  184. -(void)initWithFrame:(CGRect)arg1 {
  185. %orig;
  186. [self removeFromSuperview];
  187. }
  188. -(CGFloat)desiredVisibilityDuration {
  189. return 0;
  190. }
  191. -(void)setBatteryVisible:(BOOL)arg1 {
  192. %orig(NO);
  193. }
  194. %end