Device battery indicators on your Lock Screen
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

170 linhas
4.5KB

  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. battery.heightConstraint.active = NO;
  74. NSLog(@"kai: 1st time, assigning to %d", 500);
  75. battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:500];
  76. battery.heightConstraint.active = YES;
  77. } else {
  78. int height = (battery.number * 85);
  79. if(height!=0) {
  80. battery.heightConstraint.active = NO;
  81. NSLog(@"kai: setting to %d", height);
  82. battery.heightConstraint.constant = height;
  83. battery.heightConstraint.active = YES;
  84. UIStackView *s = [self stackView];
  85. s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
  86. }
  87. }
  88. }];
  89. }
  90. %new
  91. -(void)KaiInfo {
  92. //NSLog(@"Kai: Updating Info");
  93. [[KAIBattery sharedInstance] updateBattery];
  94. [self KaiUpdate];
  95. }
  96. %end
  97. %hook BCBatteryDevice
  98. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  99. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  100. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  101. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  102. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  103. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  104. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  105. return %orig;
  106. }
  107. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  108. dispatch_async(dispatch_get_main_queue(), ^{
  109. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  110. });
  111. }
  112. %end
  113. %hook _CSSingleBatteryChargingView
  114. -(void)initWithFrame:(CGRect)arg1 {
  115. %orig;
  116. [self removeFromSuperview];
  117. }
  118. -(CGFloat)desiredVisibilityDuration {
  119. return 0;
  120. }
  121. -(void)setBatteryVisible:(BOOL)arg1 {
  122. %orig(NO);
  123. }
  124. %end