Device battery indicators on your Lock Screen
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

136 linhas
3.4KB

  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 _CSSingleBatteryChargingView
  77. -(void)initWithFrame:(CGRect)arg1 {
  78. %orig;
  79. [self removeFromSuperview];
  80. }
  81. -(CGFloat)desiredVisibilityDuration {
  82. return 0;
  83. }
  84. -(void)setBatteryVisible:(BOOL)arg1 {
  85. %orig(NO);
  86. }
  87. %end
  88. %ctor {
  89. preferencesChanged();
  90. CFNotificationCenterAddObserver(
  91. CFNotificationCenterGetDarwinNotifyCenter(),
  92. &observer,
  93. (CFNotificationCallback)applyPrefs,
  94. kSettingsChangedNotification,
  95. NULL,
  96. CFNotificationSuspensionBehaviorDeliverImmediately
  97. );
  98. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  99. if(enabled) {
  100. %init(KAITarget = cls);
  101. }
  102. }