Device battery indicators on your Lock Screen
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

145 行
4.0KB

  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 CSBatteryChargingView
  79. +(id)batteryChargingViewWithSingleBattery {
  80. NSLog(@"kai: here bro: %@", [NSThread callStackSymbols]);
  81. [UIPasteboard generalPasteboard].string = [NSString stringWithFormat:@"kai: here bro: %@", [NSThread callStackSymbols]];
  82. return nil;
  83. }
  84. +(id)batteryChargingViewWithDoubleBattery {
  85. NSLog(@"kai: here bro: %@", [NSThread callStackSymbols]);
  86. [UIPasteboard generalPasteboard].string = [NSString stringWithFormat:@"kai: here bro: %@", [NSThread callStackSymbols]];
  87. return nil;
  88. }
  89. -(CGFloat)desiredVisibilityDuration {
  90. return 0;
  91. }
  92. -(void)setBatteryVisible:(BOOL)arg1 {
  93. %orig(NO);
  94. }
  95. %end
  96. %ctor {
  97. preferencesChanged();
  98. CFNotificationCenterAddObserver(
  99. CFNotificationCenterGetDarwinNotifyCenter(),
  100. &observer,
  101. (CFNotificationCallback)applyPrefs,
  102. kSettingsChangedNotification,
  103. NULL,
  104. CFNotificationSuspensionBehaviorDeliverImmediately
  105. );
  106. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  107. if(enabled) {
  108. %init(KAITarget = cls);
  109. }
  110. }