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.

147 lines
3.9KB

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