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.

152 lines
4.5KB

  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, assign) BOOL hasKai;
  13. @property (nonatomic, assign) NSInteger previousKaiCount;
  14. -(UIStackView *)stackView;
  15. -(void)setStackView:(UIStackView *)arg1;
  16. -(void)KaiUpdate;
  17. @end
  18. @interface CSMainPageView : UIView
  19. -(void)updateForPresentation:(id)arg1;
  20. @end
  21. @interface _CSSingleBatteryChargingView : UIView
  22. @end
  23. @interface NCNotificationListView : UIView
  24. @end
  25. BOOL setFrame = NO;
  26. CGRect original = CGRectMake(0,0,0,0);
  27. CGRect originalBattery;
  28. %hook CSAdjunctListView
  29. %property (nonatomic, assign) BOOL hasKai;
  30. %property (nonatomic, assign) NSInteger previousKaiCount;
  31. -(void)_layoutStackView {
  32. //NSLog(@"Kai: Laying out stack view");
  33. [self KaiUpdate];
  34. %orig;
  35. }
  36. -(void)setStackView:(UIStackView *)arg1 {
  37. //NSLog(@"Kai: Updating setting stack view");
  38. if(!self.hasKai) {
  39. KAIBattery *battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, 0, UIScreen.mainScreen.bounds.size.width, 85)];
  40. battery.translatesAutoresizingMaskIntoConstraints = NO;
  41. [battery.leftAnchor constraintEqualToAnchor:battery.leftAnchor constant:0].active = YES;
  42. [battery.topAnchor constraintEqualToAnchor:battery.topAnchor constant:0].active = YES;
  43. [battery.widthAnchor constraintEqualToConstant:[self stackView].frame.size.width - 16].active = YES;
  44. originalBattery = battery.frame;
  45. original = [self stackView].frame;
  46. setFrame = YES;
  47. self.previousKaiCount = 0;
  48. self.hasKai = YES;
  49. [[NSNotificationCenter defaultCenter] addObserver:self
  50. selector:@selector(KaiInfo)
  51. name:@"KaiInfoChanged"
  52. object:nil];
  53. //[self addSubview:[KAIBattery sharedInstance]];
  54. [[KAIBattery sharedInstance] darkLightMode];
  55. }
  56. UIStackView *newView = arg1;
  57. if(![arg1.subviews containsObject:[KAIBattery sharedInstance]]) {
  58. [newView addArrangedSubview:[KAIBattery sharedInstance]];
  59. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,359,80)];
  60. [view setBackgroundColor:[UIColor redColor]];
  61. //[view setIntrinsicContentSize:CGSizeMake(359,80)];
  62. [newView addArrangedSubview:view];
  63. }
  64. %orig(newView);
  65. //%orig(arg1);
  66. }
  67. %new
  68. -(void)KaiUpdate {
  69. [[KAIBattery sharedInstance] darkLightMode];
  70. KAIBattery *battery = [KAIBattery sharedInstance];
  71. //battery.translatesAutoresizingMaskIntoConstraints = YES;
  72. battery.frame = CGRectMake(
  73. originalBattery.origin.x,
  74. originalBattery.origin.y,
  75. originalBattery.size.width,
  76. (battery.number * 85)
  77. );
  78. battery.translatesAutoresizingMaskIntoConstraints = NO;
  79. [battery.leftAnchor constraintEqualToAnchor:battery.leftAnchor constant:0].active = YES;
  80. [battery.topAnchor constraintEqualToAnchor:battery.topAnchor constant:0].active = YES;
  81. [battery.widthAnchor constraintEqualToConstant:[self stackView].frame.size.width - 16].active = YES;
  82. [battery.heightAnchor constraintEqualToConstant:(battery.number * 85)].active = YES;
  83. }
  84. %new
  85. -(void)KaiInfo {
  86. NSLog(@"Kai: Updating Info");
  87. [[KAIBattery sharedInstance] updateBattery];
  88. [self KaiUpdate];
  89. }
  90. %end
  91. %hook BCBatteryDevice
  92. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  93. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  94. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  95. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  96. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  97. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  98. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  99. return %orig;
  100. }
  101. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  102. dispatch_async(dispatch_get_main_queue(), ^{
  103. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  104. });
  105. }
  106. %end
  107. %hook _CSSingleBatteryChargingView
  108. -(void)initWithFrame:(CGRect)arg1 {
  109. %orig;
  110. [self removeFromSuperview];
  111. }
  112. -(CGFloat)desiredVisibilityDuration {
  113. return 0;
  114. }
  115. -(void)setBatteryVisible:(BOOL)arg1 {
  116. %orig(NO);
  117. }
  118. %end