Device battery indicators on your Lock Screen
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

KAIBatteryPlatter.mm 7.6KB

il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #import "KAIBatteryPlatter.h"
  2. KAIBatteryPlatter *instance;
  3. NSTimer *queueTimer = nil;
  4. @implementation KAIBatteryPlatter
  5. -(instancetype)initWithFrame:(CGRect)arg1 {
  6. self = [super initWithFrame:arg1];
  7. instance = self;
  8. if (self) {
  9. self.stack = [[KAIStackView alloc] init];
  10. self.stack.axis = kaiAlign==0 ? 1 : 0;
  11. self.stack.distribution = 0;
  12. self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal;
  13. self.stack.alignment = 0;
  14. self.oldCountOfDevices = -100;
  15. self.queued = NO;
  16. [self setMinimumZoomScale:1];
  17. [self setMaximumZoomScale:1];
  18. [self addSubview:self.stack];
  19. [self setContentSize:self.stack.frame.size];
  20. [self setContentOffset:CGPointMake(0,0)];
  21. //[self setDelegate:self];
  22. [self updateBattery];
  23. }
  24. return self;
  25. }
  26. long long batteryPercentage;
  27. long long lastPercentage;
  28. -(void)updateBattery {
  29. if(!self.stack.widthAnchor) {
  30. [self.stack.widthAnchor constraintEqualToAnchor:self.widthAnchor].active = YES;
  31. }
  32. dispatch_async(dispatch_get_main_queue(), ^{
  33. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  34. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  35. if(self.oldCountOfDevices == -100) {
  36. self.oldCountOfDevices = [devices count] + 1;
  37. }
  38. if(!self.isUpdating && self.oldCountOfDevices != 0 && ([devices count] + 1 == self.oldCountOfDevices || [devices count] - 1 == self.oldCountOfDevices || [devices count] == self.oldCountOfDevices)) {
  39. //if(!self.isUpdating) {
  40. self.isUpdating = YES;
  41. for (BCBatteryDevice *device in devices) {
  42. KAIBatteryCell *cell = [device kaiCellForDevice];
  43. BOOL charging = MSHookIvar<long long>(device, "_charging");
  44. BOOL internal = MSHookIvar<BOOL>(device, "_internal");
  45. BOOL shouldAdd = NO;
  46. if(showAll) {
  47. shouldAdd = YES;
  48. } else if(showAllMinusInternal && !internal) {
  49. shouldAdd = YES;
  50. } else if(!showAll && charging) {
  51. shouldAdd = YES;
  52. }
  53. if(![self.stack.subviews containsObject:cell] && shouldAdd && [devices containsObject:device]) {
  54. //[cell setFrame:CGRectMake(0,0,self.frame.size.width, bannerHeight)];
  55. cell.alpha = 0;
  56. [self.stack addSubview:cell];
  57. [self.stack addArrangedSubview:cell];
  58. [UIView animateWithDuration:0.3 animations:^{
  59. cell.alpha = 1;
  60. }];
  61. } else if([self.stack.subviews containsObject:cell] && !shouldAdd){
  62. [UIView animateWithDuration:0.3 animations:^{
  63. cell.alpha = 0;
  64. } completion:^(BOOL finished) {
  65. [cell removeFromSuperview];
  66. [self.stack removeArrangedSubview:cell];
  67. cell.alpha = 1;
  68. }];
  69. }
  70. }
  71. for(KAIBatteryCell *cell in self.stack.subviews) {
  72. if(![devices containsObject:cell.device]) {
  73. [UIView animateWithDuration:0.3 animations:^{
  74. cell.alpha = 0;
  75. } completion:^(BOOL finished) {
  76. [cell removeFromSuperview];
  77. [self.stack removeArrangedSubview:cell];
  78. cell.alpha = 1;
  79. }];
  80. }
  81. }
  82. queueTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(dispatchQueue) userInfo:nil repeats:NO];
  83. //self.isUpdating = NO;
  84. } else if(self.isUpdating) {
  85. self.queued = YES;
  86. }
  87. self.oldCountOfDevices = [devices count];
  88. self.number = [self.stack.subviews count];
  89. if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  90. [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
  91. }
  92. });
  93. }
  94. -(void)setContentOffset:(CGPoint)arg1 {
  95. [super setContentOffset:CGPointMake(arg1.x, 0)];
  96. }
  97. -(void)setNumber:(NSInteger)arg1 {
  98. _number = arg1;
  99. [UIView animateWithDuration:0.3 animations:^{
  100. if(!self.heightConstraint) {
  101. self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
  102. self.stack.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
  103. self.heightConstraint.active = YES;
  104. self.stack.heightConstraint.active = YES;
  105. [self setContentSize:self.stack.frame.size];
  106. } else {
  107. int height = (self.number * (bannerHeight + spacing));
  108. if(kaiAlign==0 && [self.superview.subviews count]>1) {
  109. height = (self.number * (bannerHeight + spacing)) - spacing;
  110. } else {
  111. height = bannerHeight + spacing;
  112. }
  113. self.heightConstraint.constant = height;
  114. self.stack.heightConstraint.constant = height;
  115. UIStackView *s = (UIStackView *)(self.superview);
  116. s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
  117. //literally does nothing but makes the stack view lay itself out (doesnt adjust frame because translatesAutoreszingMaskIntoConstraints = NO on stack views)
  118. [self setContentSize:self.stack.frame.size];
  119. }
  120. }];
  121. }
  122. -(void)addSubview:(UIView *)view {
  123. [super addSubview:view];
  124. self.number = [self.stack.subviews count];
  125. if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  126. [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
  127. }
  128. if(textColor==0 && [view respondsToSelector:@selector(updateInfo)]) {
  129. KAIBatteryCell *cell = (KAIBatteryCell *)view;
  130. if(@available(iOS 12.0, *)) {
  131. if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  132. [cell.label setTextColor:[UIColor whiteColor]];
  133. [cell.percentLabel setTextColor:[UIColor whiteColor]];
  134. } else if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
  135. [cell.label setTextColor:[UIColor blackColor]];
  136. [cell.percentLabel setTextColor:[UIColor blackColor]];
  137. }
  138. }
  139. }
  140. }
  141. -(void)layoutSubviews {
  142. if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  143. [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
  144. }
  145. }
  146. -(void)refreshForPrefs {
  147. self.stack.spacing = kaiAlign==0 ? 0 : spacingHorizontal;
  148. [self setContentSize:self.stack.frame.size];
  149. for( UIView *view in self.stack.subviews ) {
  150. @try {
  151. [view removeFromSuperview];
  152. } @catch (NSException *exception) {
  153. //Panik
  154. }
  155. }
  156. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  157. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  158. for(BCBatteryDevice *device in devices) {
  159. [device resetKaiCellForNewPrefs];
  160. }
  161. //self.spacing = spacing;
  162. [self updateBattery];
  163. }
  164. -(void)dispatchQueue {
  165. self.isUpdating = NO;
  166. if(self.queued) {
  167. [self updateBattery];
  168. if([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  169. [(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
  170. }
  171. self.queued = NO;
  172. }
  173. [queueTimer invalidate];
  174. queueTimer = nil;
  175. }
  176. +(KAIBatteryPlatter *)sharedInstance {
  177. return instance;
  178. }
  179. @end