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

Kai.xm 4.8KB

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