Device battery indicators on your Lock Screen
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

177 lines
5.4KB

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