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.

148 lines
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. @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. /*[KAIBattery sharedInstance].translatesAutoresizingMaskIntoConstraints = NO;
  33. [[KAIBattery sharedInstance].leftAnchor constraintEqualToAnchor:[KAIBattery sharedInstance].leftAnchor].active = YES;
  34. [[KAIBattery sharedInstance].topAnchor constraintEqualToAnchor:[KAIBattery sharedInstance].topAnchor].active = YES;
  35. [[KAIBattery sharedInstance].widthAnchor constraintEqualToConstant:UIScreen.mainScreen.bounds.size.width].active = YES;
  36. [[KAIBattery sharedInstance].heightAnchor constraintEqualToConstant:([KAIBattery sharedInstance].number * 85)].active = YES;*/
  37. NSLog(@"Kai: Laying out stack view");
  38. //[[KAIBattery sharedInstance].heightAnchor constraintEqualToConstant:([KAIBattery sharedInstance].number * 85)].active = YES;
  39. //%orig;
  40. [self KaiUpdate];
  41. %orig;
  42. }
  43. -(void)setStackView:(UIStackView *)arg1 {
  44. NSLog(@"Kai: Updating setting stack view");
  45. if(!self.hasKai) {
  46. KAIBattery *battery = [[KAIBattery alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 85)];
  47. /*battery.translatesAutoresizingMaskIntoConstraints = NO;
  48. [battery.leftAnchor constraintEqualToAnchor:battery.leftAnchor constant:0].active = YES;
  49. [battery.topAnchor constraintEqualToAnchor:battery.topAnchor constant:0].active = YES;
  50. [battery.widthAnchor constraintEqualToConstant:[self stackView].frame.size.width - 16].active = YES;*/
  51. originalBattery = battery.frame;
  52. original = self.frame;
  53. setFrame = YES;
  54. self.previousKaiCount = 0;
  55. self.hasKai = YES;
  56. [[NSNotificationCenter defaultCenter] addObserver:self
  57. selector:@selector(KaiInfo)
  58. name:@"KaiInfoChanged"
  59. object:nil];
  60. [[KAIBattery sharedInstance] darkLightMode];
  61. }
  62. UIStackView *newView = arg1;
  63. if(![arg1.subviews containsObject:[KAIBattery sharedInstance]]) {
  64. [newView addArrangedSubview:[KAIBattery sharedInstance]];
  65. }
  66. //[self addSubview:[KAIBattery sharedInstance]];
  67. %orig(newView);
  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. }
  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