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

Kai.xm 5.0KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #import "Kai.h"
  2. %hook KAITarget //This class is defined in %ctor, KAITarget is not a class name.
  3. %property (nonatomic, assign) BOOL hasKai;
  4. -(void)_layoutStackView {
  5. NSInteger lastSlot = [[self stackView].subviews count] -1;
  6. //this code is used to determine if kai is at the bottom of the stack view
  7. if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) {
  8. //if it is not, but the option to have kai below music is on, i simply remove from it's current pos.
  9. //and insert into last slot.
  10. [[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]];
  11. [[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot];
  12. }
  13. //makes kai lay itself out when the stack does
  14. NSLog(@"kai: laying out stack view");
  15. [self KaiUpdate];
  16. %orig;
  17. }
  18. -(void)setStackView:(UIStackView *)arg1 {
  19. if(!KAISelf.hasKai) {
  20. KAIBattery *battery = [[KAIBattery alloc] init];
  21. //Add noti observer
  22. [[NSNotificationCenter defaultCenter] addObserver:self
  23. selector:@selector(KaiInfo)
  24. name:@"KaiInfoChanged"
  25. object:nil];
  26. KAISelf.hasKai = YES;
  27. if(![arg1.subviews containsObject:battery]) { //if not added
  28. //add kai to the stack view
  29. [arg1 addArrangedSubview:battery];
  30. }
  31. //send the adjusted stackview as arg1
  32. %orig(arg1);
  33. }
  34. }
  35. %new
  36. -(void)KaiUpdate {
  37. KAIBattery *battery = [KAIBattery sharedInstance];
  38. battery.number = [battery.subviews count];
  39. [UIView animateWithDuration:0.3 animations:^{
  40. if(!battery.heightConstraint) {
  41. battery.heightConstraint.active = NO;
  42. battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:85];
  43. //set an initial constraint
  44. battery.heightConstraint.active = YES;
  45. } else {
  46. int height = (battery.number * (bannerHeight + spacing)); //big brain math
  47. battery.heightConstraint.active = NO; //deactivation
  48. battery.heightConstraint.constant = height;
  49. battery.heightConstraint.active = YES; //forcing reactivation
  50. UIStackView *s = [self stackView];
  51. s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
  52. //literally does nothing but makes the stack view lay itself out (doesnt adjust frame because translatesAutoreszingMaskIntoConstraints = NO on stack views)
  53. }
  54. }];
  55. }
  56. %new
  57. -(void)KaiInfo {
  58. if(!isUpdating) {
  59. isUpdating = YES;
  60. //NSLog(@"kai: kai info will update");
  61. dispatch_async(dispatch_get_main_queue(), ^{
  62. [[KAIBattery sharedInstance] updateBattery];
  63. [self KaiUpdate];
  64. isUpdating = NO;
  65. });
  66. /*isUpdating = YES;
  67. [UIView animateWithDuration:0.3 animations:^{
  68. //nice fade out
  69. [KAIBattery sharedInstance].alpha = 0;
  70. } completion:^(BOOL finished){
  71. [[KAIBattery sharedInstance] updateBattery];
  72. [self KaiUpdate];
  73. [UIView animateWithDuration:0.35 animations:^{
  74. //fade back in
  75. [KAIBattery sharedInstance].alpha = 1;
  76. } completion:^(BOOL finished){
  77. isUpdating = NO;
  78. }];
  79. }];*/
  80. }
  81. }
  82. %end
  83. %hook BCBatteryDevice
  84. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  85. //Posts a notification to self when these keys change
  86. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  87. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  88. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  89. return %orig;
  90. }
  91. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  92. dispatch_async(dispatch_get_main_queue(), ^{
  93. //sends the noti to update battery info
  94. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  95. });
  96. }
  97. %end
  98. %hook KAICSTarget //Again, not a class
  99. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
  100. if(hideChargingAnimation) {
  101. //Yeah bro this just makes the method never call to show the charging thing
  102. %orig(NO,NO,NO);
  103. }
  104. }
  105. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { //might just be ios12
  106. if(hideChargingAnimation) {
  107. //Same idea
  108. %orig(NO,NO,NO,NO);
  109. }
  110. }
  111. %end
  112. %ctor {
  113. preferencesChanged();
  114. CFNotificationCenterAddObserver(
  115. CFNotificationCenterGetDarwinNotifyCenter(),
  116. &observer,
  117. (CFNotificationCallback)applyPrefs,
  118. kSettingsChangedNotification,
  119. NULL,
  120. CFNotificationSuspensionBehaviorDeliverImmediately
  121. );
  122. //Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
  123. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  124. Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSCoverSheetViewController") class]) : ([objc_getClass("SBDashBoardViewController") class]);
  125. if(enabled) {
  126. %init(KAITarget = cls, KAICSTarget = CSCls); //BIG BRAIN BRO!!
  127. }
  128. }