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.

140 lines
5.1KB

  1. #import "KAIBatteryStack.h"
  2. KAIBatteryStack *instance;
  3. //NSMutableArray *showingCells = [[NSMutableArray alloc] init];
  4. @implementation KAIBatteryStack
  5. -(instancetype)init {
  6. self = [super init];
  7. instance = self;
  8. if (self) {
  9. self.displayingDevices = [[NSMutableArray alloc] init];
  10. self.axis = 1;
  11. self.distribution = 0;
  12. self.spacing = 0;
  13. self.alignment = 0;
  14. [self updateBattery];
  15. //self.clipsToBounds = YES;
  16. self.userInteractionEnabled = NO;
  17. }
  18. return self;
  19. }
  20. long long batteryPercentage;
  21. long long lastPercentage;
  22. -(void)updateBattery {
  23. /*
  24. self.spacing = spacing;
  25. dispatch_async(dispatch_get_main_queue(), ^{
  26. //NSLog(@"kai: battery platter called to update");
  27. if(!self.isUpdating) {
  28. //NSLog(@"kai: IS Updating");
  29. self.isUpdating = YES;
  30. //self.number = 0;
  31. float y = 0;
  32. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  33. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  34. if([devices count]!=0) {
  35. //NSLog(@"kai: info is good, will proceed");
  36. float ytwo = 0;
  37. for(KAIBatteryCell *cell in self.subviews) {
  38. if([cell respondsToSelector:@selector(updateInfo)] && ![devices containsObject:cell.device]) { //to confirm is a cell and battery device does not exist
  39. //dispatch_async(dispatch_get_main_queue(), ^{
  40. [UIView animateWithDuration:0.2 animations:^{
  41. cell.alpha = 0;
  42. } completion:^(BOOL finished){
  43. [cell removeFromSuperview];
  44. }];
  45. //});
  46. } else if([cell respondsToSelector:@selector(updateInfo)]) {
  47. cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
  48. [cell updateInfo];
  49. ytwo+= bannerHeight + spacing;
  50. }
  51. }
  52. for (BCBatteryDevice *device in devices) {
  53. NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
  54. //double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
  55. BOOL charging = MSHookIvar<long long>(device, "_charging");
  56. //BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  57. BOOL shouldAdd = NO;
  58. if(showAll) {
  59. shouldAdd = YES;
  60. //NSLog(@"Kai: SHOULD ADD");
  61. } else if(!showAll && charging) {
  62. shouldAdd = YES;
  63. //NSLog(@"Kai: SHOULD ADD");
  64. }
  65. KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device frameToCreateNew:CGRectMake(0, y, self.frame.size.width, bannerHeight)];
  66. cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
  67. if(cell) {
  68. cell.device = device;
  69. //cell.frame = cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight); //bro im like creating my own stack view
  70. //[cell updateInfo];
  71. }
  72. if(shouldAdd && [deviceName length]!=0) {
  73. if(![self.subviews containsObject:cell]) {
  74. cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
  75. cell.alpha = 0;
  76. [self addSubview:cell];
  77. [UIView animateWithDuration:0.3 animations:^{
  78. cell.alpha = 1;
  79. }];
  80. }
  81. y+=bannerHeight + spacing;
  82. } else if(!shouldAdd) {
  83. //dispatch_async(dispatch_get_main_queue(), ^{
  84. [UIView animateWithDuration:0.2 animations:^{
  85. cell.alpha = 0;
  86. } completion:^(BOOL finished){
  87. [cell removeFromSuperview];
  88. }];
  89. //});
  90. }
  91. }
  92. //[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES;
  93. self.number = [self.subviews count];
  94. //[(CSAdjunctListView *)self.superview.superview KaiUpdate];
  95. }
  96. self.isUpdating = NO;
  97. //NSLog(@"kai: finished update");
  98. //[(CSAdjunctListView *)self.superview.superview KaiUpdate];
  99. [(CSAdjunctListView *)self.superview.superview performSelector:@selector(KaiUpdate) withObject:(CSAdjunctListView *)self.superview.superview afterDelay:0.2];
  100. }
  101. });*/
  102. self.number = [self.subviews count];
  103. }
  104. -(void)removeAllAndRefresh {
  105. for( UIView *view in self.subviews ) {
  106. @try {
  107. [view removeFromSuperview];
  108. } @catch (NSException *exception) {
  109. //Panik
  110. }
  111. }
  112. [KAIBatteryCell resetArray];
  113. //self.displayingDevices = [[NSMutableArray alloc] init];
  114. //addedCells = nil;
  115. [self updateBattery];
  116. }
  117. +(KAIBatteryStack *)sharedInstance {
  118. return instance;
  119. }
  120. @end