Device battery indicators on your Lock Screen
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

151 行
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. [self.battery updateBattery];
  53. }
  54. object.frame = CGRectMake(
  55. original.origin.x,
  56. original.origin.y + (self.battery.number * 90),
  57. original.size.width,
  58. original.size.height
  59. );
  60. //[self.battery updateBattery];
  61. /*
  62. NSArray* subViews = self.subviews;
  63. for( UIView *view in subViews ) {
  64. if([view isMemberOfClass:[objc_getClass("UILabel") class]] || [view isMemberOfClass:[objc_getClass("_UIBatteryView") class]] || [view isKindOfClass:[objc_getClass("UIImageView") class]]) {
  65. @try {
  66. [view removeFromSuperview];
  67. } @catch (NSException *exception) {
  68. //Panik
  69. }
  70. }
  71. }
  72. /*BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  73. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  74. for (BCBatteryDevice *device in devices) {
  75. NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
  76. double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
  77. BOOL charging = MSHookIvar<long long>(device, "_charging");
  78. BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  79. if(charging) {
  80. NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
  81. UILabel *label = [[UILabel alloc] init];
  82. [label setFont:[UIFont systemFontOfSize:18]];
  83. [label setTextColor:[UIColor whiteColor]];
  84. label.lineBreakMode = NSLineBreakByWordWrapping;
  85. label.numberOfLines = 0;
  86. [label setText:labelText];
  87. [self addSubview:label];
  88. _UIBatteryView *battery = [[_UIBatteryView alloc] init];
  89. battery.chargePercent = (batteryPercentage*0.01);
  90. UILabel *percentLabel = [[UILabel alloc] init];
  91. //if(self.percentEnabled) {
  92. // battery.showsPercentage = YES;
  93. // } else {
  94. battery.showsPercentage = NO;
  95. [percentLabel setFont:[UIFont systemFontOfSize:14]];
  96. [percentLabel setTextColor:[UIColor whiteColor]];
  97. percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  98. [percentLabel setTextAlignment:NSTextAlignmentRight];
  99. percentLabel.numberOfLines = 0;
  100. [percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  101. [self addSubview:percentLabel];
  102. //}
  103. if(charging) battery.chargingState = 2;
  104. if(LPM) battery.saverModeActive = YES;
  105. if(kCFCoreFoundationVersionNumber > 1600) {
  106. [battery setBodyColorAlpha:1.0];
  107. [battery setPinColorAlpha:1.0];
  108. }
  109. [self addSubview:battery];
  110. UIImage *glyph = [device glyph];
  111. UIImageView *glyphView = [[UIImageView alloc] init];
  112. //if(self.glyphsEnabled) {
  113. glyphView.contentMode = UIViewContentModeScaleAspectFit;
  114. [glyphView setImage:glyph];
  115. [self addSubview:glyphView];
  116. //}
  117. label.frame = CGRectMake(10,20,275,25);
  118. glyphView.frame = CGRectMake(27,25,17,15);
  119. battery.frame = CGRectMake(325,25,20,10);
  120. percentLabel.frame = CGRectMake(285,25,36,12);
  121. }
  122. }*/
  123. }
  124. %end