Device battery indicators on your Lock Screen
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

143 lines
3.8KB

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