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.

141 lines
3.6KB

  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. UIStackView *newView = arg1;
  18. if(![arg1.subviews containsObject:battery]) {
  19. [newView addArrangedSubview:battery];
  20. }
  21. %orig(newView);
  22. }
  23. }
  24. %new
  25. -(void)KaiUpdate {
  26. KAIBattery *battery = [KAIBattery sharedInstance];
  27. [UIView animateWithDuration:0.3 animations:^{
  28. if(!battery.heightConstraint) {
  29. battery.heightConstraint.active = NO;
  30. NSLog(@"kai: 1st time, assigning to %d", 500);
  31. battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:500];
  32. battery.heightConstraint.active = YES;
  33. } else {
  34. int height = (battery.number * (bannerHeight + spacing));
  35. battery.heightConstraint.active = NO;
  36. NSLog(@"kai: setting to %d", height);
  37. battery.heightConstraint.constant = height;
  38. battery.heightConstraint.active = YES;
  39. UIStackView *s = [self stackView];
  40. s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
  41. }
  42. }];
  43. }
  44. %new
  45. -(void)KaiInfo {
  46. if(!isUpdating) {
  47. isUpdating = YES;
  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. } completion:^(BOOL finished){
  56. isUpdating = NO;
  57. }];
  58. }];
  59. }
  60. }
  61. %end
  62. %hook BCBatteryDevice
  63. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  64. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  65. //[self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  66. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  67. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  68. return %orig;
  69. }
  70. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  71. dispatch_async(dispatch_get_main_queue(), ^{
  72. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  73. });
  74. }
  75. %end
  76. %hook CSBatteryChargingView
  77. +(id)batteryChargingViewWithSingleBattery {
  78. //NSLog(@"kai: here bro: %@", [NSThread callStackSymbols]);
  79. //[UIPasteboard generalPasteboard].string = [NSString stringWithFormat:@"kai: here bro: %@", [NSThread callStackSymbols]];
  80. return nil;
  81. }
  82. +(id)batteryChargingViewWithDoubleBattery {
  83. return nil;
  84. }
  85. -(CGFloat)desiredVisibilityDuration {
  86. return 0;
  87. }
  88. -(void)setBatteryVisible:(BOOL)arg1 {
  89. %orig(NO);
  90. }
  91. %end
  92. %ctor {
  93. preferencesChanged();
  94. CFNotificationCenterAddObserver(
  95. CFNotificationCenterGetDarwinNotifyCenter(),
  96. &observer,
  97. (CFNotificationCallback)applyPrefs,
  98. kSettingsChangedNotification,
  99. NULL,
  100. CFNotificationSuspensionBehaviorDeliverImmediately
  101. );
  102. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  103. if(enabled) {
  104. %init(KAITarget = cls);
  105. }
  106. }