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.

159 lines
4.3KB

  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. //when you setup your constraint:
  39. //battery.translatesAutoresizingMaskIntoConstraints = NO;
  40. //[battery.widthAnchor constraintEqualToAnchor:[self stackView].widthAnchor].active = YES;
  41. //[battery.heightAnchor constraintEqualToConstant:(battery.number * 85)].active = YES;
  42. //[battery.heightAnchor constraintEqualToConstant:100].active = YES;
  43. originalBattery = battery.frame;
  44. original = [self stackView].frame;
  45. [[NSNotificationCenter defaultCenter] addObserver:self
  46. selector:@selector(KaiInfo)
  47. name:@"KaiInfoChanged"
  48. object:nil];
  49. self.hasKai = YES;
  50. [[KAIBattery sharedInstance] darkLightMode];
  51. UIStackView *newView = arg1;
  52. if(![arg1.subviews containsObject:battery]) {
  53. [newView addArrangedSubview:battery];
  54. //UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,359,80)];
  55. //[view setBackgroundColor:[UIColor redColor]];
  56. //[newView addArrangedSubview:view];
  57. }
  58. %orig(newView);
  59. }
  60. }
  61. %new
  62. -(void)KaiUpdate {
  63. [[KAIBattery sharedInstance] darkLightMode];
  64. KAIBattery *battery = [KAIBattery sharedInstance];
  65. //battery.translatesAutoresizingMaskIntoConstraints = YES;
  66. //[battery.widthAnchor constraintEqualToAnchor:[self stackView].widthAnchor].active = YES;
  67. [UIView animateWithDuration:0.3 animations:^{
  68. //to disable the constraint:
  69. //battery.heightConstraint.active = NO;
  70. //to change the constant:
  71. //battery.heightConstraint.constant = (battery.number * 85);
  72. if(!battery.heightConstraint) {
  73. NSLog(@"kai: 1st time, assigning to %ld", (battery.number * 85));
  74. battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:(battery.number * 85)];
  75. battery.heightConstraint.active = YES;
  76. }
  77. NSLog(@"kai: setting to %ld", (battery.number * 85));
  78. battery.heightConstraint.constant = (battery.number * 85);
  79. }];
  80. }
  81. %new
  82. -(void)KaiInfo {
  83. //NSLog(@"Kai: Updating Info");
  84. [[KAIBattery sharedInstance] updateBattery];
  85. [self KaiUpdate];
  86. }
  87. %end
  88. %hook BCBatteryDevice
  89. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  90. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  91. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  92. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  93. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  94. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  95. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  96. return %orig;
  97. }
  98. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  99. dispatch_async(dispatch_get_main_queue(), ^{
  100. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  101. });
  102. }
  103. %end
  104. %hook _CSSingleBatteryChargingView
  105. -(void)initWithFrame:(CGRect)arg1 {
  106. %orig;
  107. [self removeFromSuperview];
  108. }
  109. -(CGFloat)desiredVisibilityDuration {
  110. return 0;
  111. }
  112. -(void)setBatteryVisible:(BOOL)arg1 {
  113. %orig(NO);
  114. }
  115. %end