Device battery indicators on your Lock Screen
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

158 lines
4.7KB

  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. UIView *placeholder = [[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)];
  59. [newView addArrangedSubview:placeholder];
  60. placeholder.translatesAutoresizingMaskIntoConstraints = NO;
  61. [placeholder.leftAnchor constraintEqualToAnchor:placeholder.leftAnchor constant:0].active = YES;
  62. [placeholder.topAnchor constraintEqualToAnchor:placeholder.topAnchor constant:0].active = YES;
  63. [placeholder.widthAnchor constraintEqualToAnchor:[self stackView].widthAnchor].active = YES;
  64. [placeholder.heightAnchor constraintEqualToConstant:[KAIBattery sharedInstance].frame.size.height].active = YES;
  65. }
  66. %orig(newView);
  67. //%orig(arg1);
  68. }
  69. %new
  70. -(void)KaiUpdate {
  71. [[KAIBattery sharedInstance] darkLightMode];
  72. KAIBattery *battery = [KAIBattery sharedInstance];
  73. //battery.translatesAutoresizingMaskIntoConstraints = YES;
  74. battery.frame = CGRectMake(
  75. originalBattery.origin.x,
  76. originalBattery.origin.y,
  77. originalBattery.size.width,
  78. (battery.number * 85)
  79. );
  80. UIStackView *stack = [self stackView];
  81. stack.frame = CGRectMake(
  82. stack.frame.origin.x,
  83. original.origin.y + (battery.number * 85),
  84. stack.frame.size.width,
  85. stack.frame.size.height
  86. );
  87. [[[self stackView].subviews objectAtIndex:0].heightAnchor constraintEqualToConstant:[KAIBattery sharedInstance].frame.size.height].active = YES;
  88. }
  89. %new
  90. -(void)KaiInfo {
  91. NSLog(@"Kai: Updating Info");
  92. [[KAIBattery sharedInstance] updateBattery];
  93. [self KaiUpdate];
  94. }
  95. %end
  96. %hook BCBatteryDevice
  97. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  98. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  99. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  100. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  101. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  102. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  103. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  104. return %orig;
  105. }
  106. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  107. dispatch_async(dispatch_get_main_queue(), ^{
  108. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  109. });
  110. }
  111. %end
  112. %hook _CSSingleBatteryChargingView
  113. -(void)initWithFrame:(CGRect)arg1 {
  114. %orig;
  115. [self removeFromSuperview];
  116. }
  117. -(CGFloat)desiredVisibilityDuration {
  118. return 0;
  119. }
  120. -(void)setBatteryVisible:(BOOL)arg1 {
  121. %orig(NO);
  122. }
  123. %end