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.

150 lines
4.6KB

  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. BOOL setFrame = NO;
  8. KAIBattery *batteryWidget;
  9. CGRect original;
  10. /*
  11. - (void)addObserver:(NSObject *)observer
  12. forKeyPath:(NSString *)keyPath
  13. options:(NSKeyValueObservingOptions)options
  14. context:(void *)context*/
  15. @interface UIApplication (Kai)
  16. +(id)sharedApplication;
  17. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  18. @end
  19. @interface CSMainPageView : UIView
  20. @property (nonatomic, strong) KAIBattery *battery;
  21. -(void)updateForPresentation:(id)arg1;
  22. @end
  23. /*
  24. %hook BCBatterDeviceController
  25. +(id)sharedInstance {
  26. [%orig addObserver:self forKeyPath:@"sortedDevices" options:NSKeyValueObservingOptionNew context:nil];
  27. return %orig;
  28. }
  29. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  30. if ([keyPath isEqualToString:@"sortedDevices"]) {
  31. [[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.weather" suspended:NO];
  32. }
  33. }
  34. %end*/
  35. %hook SBCoverSheetPrimarySlidingViewController
  36. -(void)viewWillAppear:(BOOL)arg1 {
  37. %orig;
  38. [batteryWidget updateBattery];
  39. }
  40. %end
  41. %hook CSMainPageView
  42. %property (nonatomic, strong) KAIBattery *battery;
  43. -(void)updateForPresentation:(id)arg1 {
  44. %orig;
  45. UIView *object = self;
  46. if(!setFrame) {
  47. original = self.frame;
  48. self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, 155, object.frame.size.width - 16, object.frame.size.height)];
  49. [self addSubview:self.battery];
  50. setFrame = YES;
  51. batteryWidget = self.battery;
  52. }
  53. object.frame = CGRectMake(
  54. original.origin.x,
  55. original.origin.y - (self.battery.number * 90),
  56. original.size.width,
  57. original.size.height + (self.battery.number * 90)
  58. );
  59. //[self.battery updateBattery];
  60. /*
  61. NSArray* subViews = self.subviews;
  62. for( UIView *view in subViews ) {
  63. if([view isMemberOfClass:[objc_getClass("UILabel") class]] || [view isMemberOfClass:[objc_getClass("_UIBatteryView") class]] || [view isKindOfClass:[objc_getClass("UIImageView") class]]) {
  64. @try {
  65. [view removeFromSuperview];
  66. } @catch (NSException *exception) {
  67. //Panik
  68. }
  69. }
  70. }
  71. /*BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  72. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  73. for (BCBatteryDevice *device in devices) {
  74. NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
  75. double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
  76. BOOL charging = MSHookIvar<long long>(device, "_charging");
  77. BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  78. if(charging) {
  79. NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
  80. UILabel *label = [[UILabel alloc] init];
  81. [label setFont:[UIFont systemFontOfSize:18]];
  82. [label setTextColor:[UIColor whiteColor]];
  83. label.lineBreakMode = NSLineBreakByWordWrapping;
  84. label.numberOfLines = 0;
  85. [label setText:labelText];
  86. [self addSubview:label];
  87. _UIBatteryView *battery = [[_UIBatteryView alloc] init];
  88. battery.chargePercent = (batteryPercentage*0.01);
  89. UILabel *percentLabel = [[UILabel alloc] init];
  90. //if(self.percentEnabled) {
  91. // battery.showsPercentage = YES;
  92. // } else {
  93. battery.showsPercentage = NO;
  94. [percentLabel setFont:[UIFont systemFontOfSize:14]];
  95. [percentLabel setTextColor:[UIColor whiteColor]];
  96. percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  97. [percentLabel setTextAlignment:NSTextAlignmentRight];
  98. percentLabel.numberOfLines = 0;
  99. [percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  100. [self addSubview:percentLabel];
  101. //}
  102. if(charging) battery.chargingState = 2;
  103. if(LPM) battery.saverModeActive = YES;
  104. if(kCFCoreFoundationVersionNumber > 1600) {
  105. [battery setBodyColorAlpha:1.0];
  106. [battery setPinColorAlpha:1.0];
  107. }
  108. [self addSubview:battery];
  109. UIImage *glyph = [device glyph];
  110. UIImageView *glyphView = [[UIImageView alloc] init];
  111. //if(self.glyphsEnabled) {
  112. glyphView.contentMode = UIViewContentModeScaleAspectFit;
  113. [glyphView setImage:glyph];
  114. [self addSubview:glyphView];
  115. //}
  116. label.frame = CGRectMake(10,20,275,25);
  117. glyphView.frame = CGRectMake(27,25,17,15);
  118. battery.frame = CGRectMake(325,25,20,10);
  119. percentLabel.frame = CGRectMake(285,25,36,12);
  120. }
  121. }*/
  122. }
  123. %end