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.

131 lines
3.5KB

  1. #import "Kai.h"
  2. %hook KAITarget
  3. %property (nonatomic, assign) BOOL hasKai;
  4. -(void)_layoutStackView {
  5. NSInteger lastSlot = [[self stackView].subviews count] -1;
  6. if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) {
  7. [[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]];
  8. [[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot];
  9. }
  10. [self KaiUpdate];
  11. %orig;
  12. }
  13. -(void)setStackView:(UIStackView *)arg1 {
  14. if(!KAISelf.hasKai) {
  15. KAIBattery *battery = [[KAIBattery alloc] init];
  16. [[NSNotificationCenter defaultCenter] addObserver:self
  17. selector:@selector(KaiInfo)
  18. name:@"KaiInfoChanged"
  19. object:nil];
  20. KAISelf.hasKai = YES;
  21. UIStackView *newView = arg1;
  22. if(![arg1.subviews containsObject:battery]) {
  23. [newView addArrangedSubview:battery];
  24. }
  25. %orig(newView);
  26. }
  27. }
  28. %new
  29. -(void)KaiUpdate {
  30. KAIBattery *battery = [KAIBattery sharedInstance];
  31. [UIView animateWithDuration:0.3 animations:^{
  32. if(!battery.heightConstraint) {
  33. battery.heightConstraint.active = NO;
  34. battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:85];
  35. battery.heightConstraint.active = YES;
  36. } else {
  37. int height = (battery.number * ((bannerHeight + spacing) - spacing + 5));
  38. battery.heightConstraint.active = NO;
  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. if(!isUpdating) {
  49. isUpdating = YES;
  50. [UIView animateWithDuration:0.3 animations:^{
  51. [KAIBattery sharedInstance].alpha = 0;
  52. } completion:^(BOOL finished){
  53. [[KAIBattery sharedInstance] updateBattery];
  54. [self KaiUpdate];
  55. [UIView animateWithDuration:0.35 animations:^{
  56. [KAIBattery sharedInstance].alpha = 1;
  57. } completion:^(BOOL finished){
  58. isUpdating = NO;
  59. }];
  60. }];
  61. }
  62. }
  63. %end
  64. %hook BCBatteryDevice
  65. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  66. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  67. //[self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
  68. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  69. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  70. return %orig;
  71. }
  72. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  73. dispatch_async(dispatch_get_main_queue(), ^{
  74. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  75. });
  76. }
  77. %end
  78. %hook CSCoverSheetViewController
  79. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
  80. if(hideChargingAnimation) {
  81. %orig(NO,NO,NO);
  82. }
  83. }
  84. %end
  85. %ctor {
  86. preferencesChanged();
  87. CFNotificationCenterAddObserver(
  88. CFNotificationCenterGetDarwinNotifyCenter(),
  89. &observer,
  90. (CFNotificationCallback)applyPrefs,
  91. kSettingsChangedNotification,
  92. NULL,
  93. CFNotificationSuspensionBehaviorDeliverImmediately
  94. );
  95. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  96. if(enabled) {
  97. %init(KAITarget = cls);
  98. }
  99. }