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.

178 lines
6.1KB

  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. //%orig;
  34. if(!self.hasKai) {
  35. //original = self.superview.superview.frame;
  36. KAIBattery *battery = [[KAIBattery alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)];
  37. battery.translatesAutoresizingMaskIntoConstraints = NO;
  38. [battery.leftAnchor constraintEqualToAnchor:battery.leftAnchor].active = YES;
  39. [battery.topAnchor constraintEqualToAnchor:battery.topAnchor].active = YES;
  40. [battery.widthAnchor constraintEqualToConstant:UIScreen.mainScreen.bounds.size.width].active = YES;
  41. [battery.heightAnchor constraintEqualToConstant:(battery.number * 85)].active = YES;
  42. originalBattery = battery.frame;
  43. original = self.frame;
  44. setFrame = YES;
  45. self.previousKaiCount = 0;
  46. self.hasKai = YES;
  47. [[NSNotificationCenter defaultCenter] addObserver:self
  48. selector:@selector(KaiInfo)
  49. name:@"KaiInfoChanged"
  50. object:nil];
  51. [[KAIBattery sharedInstance] darkLightMode];
  52. //CGRect frame = [self stackView].frame;
  53. //[[self stackView] setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height + ([KAIBattery sharedInstance].number * 85))];
  54. //[self setStackView:[KAIBattery sharedInstance]];
  55. }
  56. //[[self stackView].heightAnchor constraintEqualToAnchor:[self stackView].heightAnchor constant:([KAIBattery sharedInstance].number * 85)].active = YES;
  57. //self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, original.size.height + ([KAIBattery sharedInstance].number * 85));
  58. [self KaiUpdate];
  59. %orig;
  60. }
  61. -(void)setStackView:(UIStackView *)arg1 {
  62. NSLog(@"Kai: Updating setting stack view");
  63. if(!self.hasKai) {
  64. //original = self.superview.superview.frame;
  65. KAIBattery *battery = [[KAIBattery alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)];
  66. battery.translatesAutoresizingMaskIntoConstraints = NO;
  67. [battery.leftAnchor constraintEqualToAnchor:battery.leftAnchor].active = YES;
  68. [battery.topAnchor constraintEqualToAnchor:battery.topAnchor].active = YES;
  69. [battery.widthAnchor constraintEqualToConstant:UIScreen.mainScreen.bounds.size.width].active = YES;
  70. [battery.heightAnchor constraintEqualToConstant:(battery.number * 85)].active = YES;
  71. originalBattery = battery.frame;
  72. original = self.frame;
  73. setFrame = YES;
  74. self.previousKaiCount = 0;
  75. self.hasKai = YES;
  76. [[NSNotificationCenter defaultCenter] addObserver:self
  77. selector:@selector(KaiInfo)
  78. name:@"KaiInfoChanged"
  79. object:nil];
  80. [[KAIBattery sharedInstance] darkLightMode];
  81. //CGRect frame = [self stackView].frame;
  82. /*[[self stackView] setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height + ([KAIBattery sharedInstance].number * 85))];*/
  83. //[self setStackView:[KAIBattery sharedInstance]];
  84. }
  85. UIStackView *newView = arg1;
  86. if(![arg1.subviews containsObject:[KAIBattery sharedInstance]]) {
  87. //[newView addSubview:[KAIBattery sharedInstance]];
  88. [newView addArrangedSubview:[KAIBattery sharedInstance]];
  89. }
  90. //newView.frame = CGRectMake(newView.frame.origin.x, newView.frame.origin.y, newView.frame.size.width, newView.frame.size.height + [KAIBattery sharedInstance].frame.size.height);
  91. //original = newView.frame;
  92. %orig(newView);
  93. }
  94. %new
  95. -(void)KaiUpdate {
  96. /*NSLog(@"Kai: Updating Pos.");
  97. dispatch_async(dispatch_get_main_queue(), ^{
  98. [UIView animateWithDuration:0.3 animations:^{
  99. //[KAIBattery sharedInstance].frame = CGRectMake(UIScreen.mainScreen.bounds.origin.x, 0, UIScreen.mainScreen.bounds.size.width, ([KAIBattery sharedInstance].number * 85));
  100. //[KAIBattery sharedInstance].superview.frame = CGRectMake(original.origin.x, original.origin.y, original.size.width, original.size.height + ([KAIBattery sharedInstance].number * 85));
  101. }];
  102. [[KAIBattery sharedInstance] darkLightMode];
  103. });*/
  104. }
  105. %new
  106. -(void)KaiInfo {
  107. NSLog(@"Kai: Updating Info");
  108. [[KAIBattery sharedInstance] updateBattery];
  109. [self KaiUpdate];
  110. }
  111. %end
  112. %hook BCBatteryDevice
  113. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  114. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  115. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  116. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  117. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  118. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  119. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  120. return %orig;
  121. }
  122. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  123. dispatch_async(dispatch_get_main_queue(), ^{
  124. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  125. });
  126. }
  127. %end
  128. %hook _CSSingleBatteryChargingView
  129. -(void)initWithFrame:(CGRect)arg1 {
  130. %orig;
  131. [self removeFromSuperview];
  132. }
  133. -(CGFloat)desiredVisibilityDuration {
  134. return 0;
  135. }
  136. -(void)setBatteryVisible:(BOOL)arg1 {
  137. %orig(NO);
  138. }
  139. %end