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.

128 lines
3.1KB

  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 * (80 + spacing));
  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. [UIView animateWithDuration:0.3 animations:^{
  49. [KAIBattery sharedInstance].alpha = 0;
  50. } completion:^(BOOL finished){
  51. [[KAIBattery sharedInstance] updateBattery];
  52. [self KaiUpdate];
  53. [UIView animateWithDuration:0.35 animations:^{
  54. [KAIBattery sharedInstance].alpha = 1;
  55. }];
  56. }];
  57. [[KAIBattery sharedInstance] updateBattery];
  58. [self KaiUpdate];
  59. }
  60. %end
  61. %hook BCBatteryDevice
  62. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  63. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  64. [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  65. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  66. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  67. return %orig;
  68. }
  69. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  70. dispatch_async(dispatch_get_main_queue(), ^{
  71. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  72. });
  73. }
  74. %end
  75. %hook _CSSingleBatteryChargingView
  76. -(void)initWithFrame:(CGRect)arg1 {
  77. %orig;
  78. [self removeFromSuperview];
  79. }
  80. -(CGFloat)desiredVisibilityDuration {
  81. return 0;
  82. }
  83. -(void)setBatteryVisible:(BOOL)arg1 {
  84. %orig(NO);
  85. }
  86. %end
  87. %ctor {
  88. preferencesChanged();
  89. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  90. if(enabled) {
  91. %init(KAITarget = cls);
  92. }
  93. }