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.

151 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. @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. /*[KAIBattery sharedInstance].translatesAutoresizingMaskIntoConstraints = NO;
  33. [[KAIBattery sharedInstance].leftAnchor constraintEqualToAnchor:[KAIBattery sharedInstance].leftAnchor].active = YES;
  34. [[KAIBattery sharedInstance].topAnchor constraintEqualToAnchor:[KAIBattery sharedInstance].topAnchor].active = YES;
  35. [[KAIBattery sharedInstance].widthAnchor constraintEqualToConstant:UIScreen.mainScreen.bounds.size.width].active = YES;
  36. [[KAIBattery sharedInstance].heightAnchor constraintEqualToConstant:([KAIBattery sharedInstance].number * 85)].active = YES;*/
  37. NSLog(@"Kai: Laying out stack view");
  38. //%orig;
  39. [self KaiUpdate];
  40. %orig;
  41. }
  42. -(void)setStackView:(UIStackView *)arg1 {
  43. NSLog(@"Kai: Updating setting stack view");
  44. if(!self.hasKai) {
  45. //original = self.superview.superview.frame;
  46. KAIBattery *battery = [[KAIBattery alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 0)];
  47. /*battery.translatesAutoresizingMaskIntoConstraints = YES;
  48. [battery.leftAnchor constraintEqualToAnchor:battery.leftAnchor].active = YES;
  49. [battery.topAnchor constraintEqualToAnchor:battery.topAnchor].active = YES;
  50. [battery.widthAnchor constraintEqualToConstant:UIScreen.mainScreen.bounds.size.width].active = YES;
  51. [battery.heightAnchor constraintEqualToConstant:(battery.number * 85)].active = YES;*/
  52. originalBattery = battery.frame;
  53. original = self.frame;
  54. setFrame = YES;
  55. self.previousKaiCount = 0;
  56. self.hasKai = YES;
  57. [[NSNotificationCenter defaultCenter] addObserver:self
  58. selector:@selector(KaiInfo)
  59. name:@"KaiInfoChanged"
  60. object:nil];
  61. [[KAIBattery sharedInstance] darkLightMode];
  62. }
  63. UIStackView *newView = arg1;
  64. if(![arg1.subviews containsObject:[KAIBattery sharedInstance]]) {
  65. //[newView addSubview:[KAIBattery sharedInstance]];
  66. [newView addArrangedSubview:[KAIBattery sharedInstance]];
  67. }/* else if(arg1==nil) {
  68. newView = (UIStackView *)[KAIBattery sharedInstance];
  69. }*/
  70. %orig(newView);
  71. }
  72. %new
  73. -(void)KaiUpdate {
  74. [[KAIBattery sharedInstance] darkLightMode];
  75. /*KAIBattery *battery = [KAIBattery sharedInstance];
  76. battery.translatesAutoresizingMaskIntoConstraints = YES;
  77. battery.frame = CGRectMake(
  78. originalBattery.origin.x,
  79. originalBattery.origin.y,
  80. originalBattery.size.width,
  81. (battery.number * 85)
  82. );*/
  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