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.

103 lines
3.4KB

  1. #import "KAIBattery.h"
  2. KAIBattery *instance;
  3. //NSMutableArray *showingCells = [[NSMutableArray alloc] init];
  4. @implementation KAIBattery
  5. -(instancetype)init {
  6. self = [super init];
  7. instance = self;
  8. if (self) {
  9. self.displayingDevices = [[NSMutableArray alloc] init];
  10. [self updateBattery];
  11. self.userInteractionEnabled = NO;
  12. }
  13. return self;
  14. }
  15. long long batteryPercentage;
  16. long long lastPercentage;
  17. -(void)updateBattery {
  18. //dispatch_async(dispatch_get_main_queue(), ^{
  19. //NSLog(@"kai: battery platter called to update");
  20. if(!self.isUpdating) {
  21. self.isUpdating = YES;
  22. self.number = 0;
  23. float y = 0;
  24. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  25. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  26. for(KAIBatteryCell *cell in self.subviews) {
  27. if([cell respondsToSelector:@selector(updateInfo)] && ![devices containsObject:cell.device]) { //to confirm is a cell and battery device does not exist
  28. [cell removeFromSuperview];
  29. } else if([cell respondsToSelector:@selector(updateInfo)]) {
  30. [cell updateInfo];
  31. }
  32. }
  33. for (BCBatteryDevice *device in devices) {
  34. NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
  35. //double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
  36. BOOL charging = MSHookIvar<long long>(device, "_charging");
  37. //BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  38. BOOL shouldAdd = NO;
  39. if(showAll) {
  40. shouldAdd = YES;
  41. //NSLog(@"Kai: SHOULD ADD");
  42. } else if(!showAll && charging) {
  43. shouldAdd = YES;
  44. //NSLog(@"Kai: SHOULD ADD");
  45. }
  46. KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device frameToCreateNew:CGRectMake(0, y, self.frame.size.width, bannerHeight)];
  47. if(cell) {
  48. cell.device = device;
  49. cell.frame = cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight); //bro im like creating my own stack view
  50. [cell updateInfo];
  51. }
  52. if(shouldAdd && [deviceName length]!=0) {
  53. if(![self.subviews containsObject:cell]) {
  54. cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
  55. [self addSubview:cell];
  56. }
  57. y+=bannerHeight + spacing;
  58. } else if(!shouldAdd) {
  59. [cell removeFromSuperview];
  60. }
  61. }
  62. //[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES;
  63. self.isUpdating = NO;
  64. self.number = [self.subviews count];
  65. [(CSAdjunctListView *)self.superview KaiUpdate];
  66. }
  67. //});
  68. }
  69. -(void)removeAllAndRefresh {
  70. for( UIView *view in self.subviews ) {
  71. @try {
  72. [view removeFromSuperview];
  73. } @catch (NSException *exception) {
  74. //Panik
  75. }
  76. }
  77. //self.displayingDevices = [[NSMutableArray alloc] init];
  78. //addedCells = nil;
  79. [self updateBattery];
  80. }
  81. +(KAIBattery *)sharedInstance {
  82. return instance;
  83. }
  84. @end