Device battery indicators on your Lock Screen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Kai.xm 3.9KB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #define KAISelf ((CSAdjunctListView *)self)
  8. @interface UIApplication (Kai)
  9. +(id)sharedApplication;
  10. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  11. @end
  12. @interface CSAdjunctListView : UIView
  13. @property (nonatomic, assign) BOOL hasKai;
  14. -(UIStackView *)stackView;
  15. -(void)setStackView:(UIStackView *)arg1;
  16. -(void)KaiUpdate;
  17. @end
  18. @interface SBDashBoardAdjunctListView : UIView
  19. @property (nonatomic, assign) BOOL hasKai;
  20. -(UIStackView *)stackView;
  21. -(void)setStackView:(UIStackView *)arg1;
  22. -(void)KaiUpdate;
  23. @end
  24. @interface CSMainPageView : UIView
  25. -(void)updateForPresentation:(id)arg1;
  26. @end
  27. @interface _CSSingleBatteryChargingView : UIView
  28. @end
  29. @interface NSLayoutConstraint (Kai)
  30. +(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ;
  31. @end
  32. %hook KAITarget
  33. %property (nonatomic, assign) BOOL hasKai;
  34. -(void)_layoutStackView {
  35. //NSLog(@"Kai: Laying out stack view");
  36. [self KaiUpdate];
  37. %orig;
  38. }
  39. -(void)setStackView:(UIStackView *)arg1 {
  40. if(!KAISelf.hasKai) {
  41. KAIBattery *battery = [[KAIBattery alloc] init];
  42. [[NSNotificationCenter defaultCenter] addObserver:self
  43. selector:@selector(KaiInfo)
  44. name:@"KaiInfoChanged"
  45. object:nil];
  46. KAISelf.hasKai = YES;
  47. [[KAIBattery sharedInstance] darkLightMode];
  48. UIStackView *newView = arg1;
  49. if(![arg1.subviews containsObject:battery]) {
  50. [newView addArrangedSubview:battery];
  51. }
  52. %orig(newView);
  53. }
  54. }
  55. %new
  56. -(void)KaiUpdate {
  57. [[KAIBattery sharedInstance] darkLightMode];
  58. KAIBattery *battery = [KAIBattery sharedInstance];
  59. [UIView animateWithDuration:0.3 animations:^{
  60. if(!battery.heightConstraint) {
  61. battery.heightConstraint.active = NO;
  62. NSLog(@"kai: 1st time, assigning to %d", 500);
  63. battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:500];
  64. battery.heightConstraint.active = YES;
  65. } else {
  66. int height = (battery.number * 85);
  67. battery.heightConstraint.active = NO;
  68. NSLog(@"kai: setting to %d", height);
  69. battery.heightConstraint.constant = height;
  70. battery.heightConstraint.active = YES;
  71. UIStackView *s = [self stackView];
  72. s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
  73. }
  74. }];
  75. }
  76. %new
  77. -(void)KaiInfo {
  78. [[KAIBattery sharedInstance] updateBattery];
  79. [self KaiUpdate];
  80. }
  81. %end
  82. %hook BCBatteryDevice
  83. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  84. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  85. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  86. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  87. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  88. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  89. return %orig;
  90. }
  91. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  92. dispatch_async(dispatch_get_main_queue(), ^{
  93. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  94. });
  95. }
  96. %end
  97. %hook _CSSingleBatteryChargingView
  98. -(void)initWithFrame:(CGRect)arg1 {
  99. %orig;
  100. [self removeFromSuperview];
  101. }
  102. -(CGFloat)desiredVisibilityDuration {
  103. return 0;
  104. }
  105. -(void)setBatteryVisible:(BOOL)arg1 {
  106. %orig(NO);
  107. }
  108. %end
  109. %ctor {
  110. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  111. %init(KAITarget = cls);
  112. }