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.

141 lines
3.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. @interface UIApplication (Kai)
  8. +(id)sharedApplication;
  9. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  10. @end
  11. @interface CSAdjunctListView : UIView
  12. @property (nonatomic, strong) KAIBattery *battery;
  13. @property (nonatomic, assign) BOOL hasKai;
  14. @property (nonatomic, assign) NSInteger previousKaiCount;
  15. -(void)KaiUpdate;
  16. @end
  17. @interface CSMainPageView : UIView
  18. -(void)updateForPresentation:(id)arg1;
  19. @end
  20. @interface _CSSingleBatteryChargingView : UIView
  21. @end
  22. /*
  23. @interface NCNotificationListView : UIView
  24. @property (nonatomic, assign) BOOL hasKai;
  25. @property (nonatomic, assign) NSInteger previousKaiCount;
  26. @end*/
  27. BOOL setFrame = NO;
  28. CGRect original;
  29. CGRect originalBattery;
  30. %hook CSAdjunctListView
  31. %property (nonatomic, strong) KAIBattery *battery;
  32. %property (nonatomic, assign) BOOL hasKai;
  33. %property (nonatomic, assign) NSInteger previousKaiCount;
  34. -(void)layoutSubviews {
  35. //%orig;
  36. if(!self.hasKai) {
  37. original = self.superview.superview.frame;
  38. self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, 0, self.frame.size.width - 16, UIScreen.mainScreen.bounds.size.width)];
  39. originalBattery = self.battery.frame;
  40. [self addSubview:self.battery];
  41. setFrame = YES;
  42. self.previousKaiCount = 0;
  43. self.hasKai = YES;
  44. [[NSNotificationCenter defaultCenter] addObserver:self
  45. selector:@selector(KaiUpdate)
  46. name:@"KaiInfoChanged"
  47. object:nil];
  48. [self.battery darkLightMode];
  49. }
  50. [self KaiUpdate];
  51. return %orig;
  52. }
  53. %new
  54. -(void)KaiUpdate {
  55. if(self.battery) {
  56. [self.battery updateBattery];
  57. dispatch_async(dispatch_get_main_queue(), ^{
  58. [UIView animateWithDuration:0.3 animations:^{
  59. //self.translatesAutoresizingMaskIntoConstraints = NO;
  60. // [self.topAnchor constraintEqualToAnchor:self.superview.topAnchor constant:(self.battery.number * 85)].active = YES;
  61. self.superview.superview.frame = CGRectMake(
  62. original.origin.x,
  63. original.origin.y + (self.battery.number * 85),
  64. original.size.width,
  65. original.size.height
  66. );
  67. /*self.battery.frame = CGRectMake(
  68. originalBattery.origin.x,
  69. originalBattery.origin.y - (self.battery.number * 85),
  70. originalBattery.size.width,
  71. originalBattery.size.height
  72. );*/
  73. }];
  74. [self.battery darkLightMode];
  75. });
  76. }
  77. }
  78. %end
  79. %hook BCBatteryDevice
  80. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  81. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  82. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  83. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  84. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  85. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  86. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  87. return %orig;
  88. }
  89. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  90. dispatch_async(dispatch_get_main_queue(), ^{
  91. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  92. });
  93. }
  94. %end
  95. %hook _CSSingleBatteryChargingView
  96. -(void)initWithFrame:(CGRect)arg1 {
  97. %orig;
  98. [self removeFromSuperview];
  99. }
  100. -(CGFloat)desiredVisibilityDuration {
  101. return 0;
  102. }
  103. -(void)setBatteryVisible:(BOOL)arg1 {
  104. %orig(NO);
  105. }
  106. %end