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.

119 lines
2.8KB

  1. #import "Kai.h"
  2. %hook KAITarget
  3. %property (nonatomic, assign) BOOL hasKai;
  4. -(void)_layoutStackView {
  5. //NSLog(@"Kai: Laying out stack view");
  6. [self KaiUpdate];
  7. %orig;
  8. }
  9. -(void)setStackView:(UIStackView *)arg1 {
  10. if(!KAISelf.hasKai) {
  11. KAIBattery *battery = [[KAIBattery alloc] init];
  12. [[NSNotificationCenter defaultCenter] addObserver:self
  13. selector:@selector(KaiInfo)
  14. name:@"KaiInfoChanged"
  15. object:nil];
  16. KAISelf.hasKai = YES;
  17. [[KAIBattery sharedInstance] darkLightMode];
  18. UIStackView *newView = arg1;
  19. if(![arg1.subviews containsObject:battery]) {
  20. [newView addArrangedSubview:battery];
  21. }
  22. %orig(newView);
  23. }
  24. }
  25. %new
  26. -(void)KaiUpdate {
  27. [[KAIBattery sharedInstance] darkLightMode];
  28. KAIBattery *battery = [KAIBattery sharedInstance];
  29. [UIView animateWithDuration:0.3 animations:^{
  30. if(!battery.heightConstraint) {
  31. battery.heightConstraint.active = NO;
  32. NSLog(@"kai: 1st time, assigning to %d", 500);
  33. battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:500];
  34. battery.heightConstraint.active = YES;
  35. } else {
  36. int height = (battery.number * 85);
  37. battery.heightConstraint.active = NO;
  38. NSLog(@"kai: setting to %d", height);
  39. battery.heightConstraint.constant = height;
  40. battery.heightConstraint.active = YES;
  41. UIStackView *s = [self stackView];
  42. s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
  43. }
  44. }];
  45. }
  46. %new
  47. -(void)KaiInfo {
  48. [[KAIBattery sharedInstance] updateBattery];
  49. [self KaiUpdate];
  50. }
  51. %end
  52. %hook BCBatteryDevice
  53. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  54. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  55. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  56. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  57. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  58. return %orig;
  59. }
  60. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  61. dispatch_async(dispatch_get_main_queue(), ^{
  62. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  63. });
  64. }
  65. %end
  66. %hook _CSSingleBatteryChargingView
  67. -(void)initWithFrame:(CGRect)arg1 {
  68. %orig;
  69. [self removeFromSuperview];
  70. }
  71. -(CGFloat)desiredVisibilityDuration {
  72. return 0;
  73. }
  74. -(void)setBatteryVisible:(BOOL)arg1 {
  75. %orig(NO);
  76. }
  77. %end
  78. %ctor {
  79. preferencesChanged();
  80. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  81. if(enabled) {
  82. %init(KAITarget = cls);
  83. }
  84. }