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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #import "Kai.h"
  2. CSAdjunctListView *list;
  3. Class mediaClass;
  4. %group main
  5. %hook Media
  6. - (void)dealloc {
  7. %orig;
  8. if(removeForMedia) {
  9. shouldBeAdded = YES;
  10. [[KAIBatteryPlatter sharedInstance] updateBattery];
  11. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  12. if(!belowMusic) { //cursed
  13. [[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  14. [[[cls sharedListViewForKai] stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
  15. }
  16. }
  17. }
  18. - (void)didMoveToSuperview {
  19. %orig;
  20. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  21. if([[[cls sharedListViewForKai] stackView].arrangedSubviews containsObject:self]) {
  22. if(belowMusic) {//cursed
  23. [[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  24. [[[cls sharedListViewForKai] stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:afterMusicIndex(cls, self)];
  25. } else {
  26. [[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  27. [[[cls sharedListViewForKai] stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
  28. }
  29. if(removeForMedia) {
  30. shouldBeAdded = NO;
  31. [[KAIBatteryPlatter sharedInstance] removeFromSuperview];
  32. [[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  33. }
  34. }
  35. }
  36. %end
  37. %hook KAITarget //This class is defined in %ctor, KAITarget is not a class name.
  38. %property (nonatomic, assign) BOOL hasKai;
  39. - (void)setClipsToBounds:(BOOL)arg1 {
  40. %orig(YES);
  41. }
  42. - (void)setStackView:(UIStackView *)arg1 {
  43. KAISelf.clipsToBounds = YES;
  44. if(!KAISelf.hasKai) {
  45. list = self;
  46. KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] initWithFrame:[self stackView].frame];
  47. //Add noti observer
  48. [[NSNotificationCenter defaultCenter] addObserver:self
  49. selector:@selector(KaiInfo)
  50. name:@"KaiInfoChanged"
  51. object:nil];
  52. KAISelf.hasKai = YES;
  53. if(![arg1.subviews containsObject:battery]) { //if not added
  54. //add kai to the stack view
  55. [arg1 addArrangedSubview:battery];
  56. }
  57. [battery updateBattery];
  58. //send the adjusted stackview as arg1
  59. %orig(arg1);
  60. }
  61. }
  62. %new
  63. - (void)KaiInfo {
  64. if(!isUpdating) {
  65. isUpdating = YES;
  66. //NSLog(@"kai: kai info will update");
  67. dispatch_async(dispatch_get_main_queue(), ^{
  68. [[KAIBatteryPlatter sharedInstance] updateBattery];
  69. if([KAIBatteryPlatter sharedInstance].number == 0) {
  70. [[KAIBatteryPlatter sharedInstance] removeFromSuperview];
  71. [[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  72. } else if(![[self stackView].subviews containsObject:[KAIBatteryPlatter sharedInstance]] && shouldBeAdded) {
  73. [[self stackView] addSubview:[KAIBatteryPlatter sharedInstance]];
  74. [[self stackView] addArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  75. }
  76. if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  77. [KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.35];
  78. }
  79. isUpdating = NO;
  80. });
  81. }
  82. }
  83. %new
  84. + (id)sharedListViewForKai {
  85. return list;
  86. }
  87. %end
  88. %hook SBCoverSheetPrimarySlidingViewController
  89. - (void)viewDidDisappear:(BOOL)animated {
  90. if(reAlignSelf)
  91. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiResetOffset" object:nil userInfo:nil];
  92. %orig;
  93. }
  94. - (void)viewDidAppear:(BOOL)animated {
  95. if(reAlignSelf)
  96. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiResetOffset" object:nil userInfo:nil];
  97. %orig;
  98. }
  99. %end
  100. %hook BCBatteryDevice
  101. %property (nonatomic, strong) KAIBatteryCell *kaiCell;
  102. - (void)setCharging:(BOOL)arg1 {
  103. //sends the noti to update battery info
  104. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  105. %orig;
  106. }
  107. - (void)setBatterySaverModeActive:(BOOL)arg1 {
  108. //sends the noti to update battery info
  109. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  110. %orig;
  111. }
  112. - (void)setPercentCharge:(NSInteger)arg1 {
  113. //sends the noti to update battery info
  114. if(arg1!=0) {
  115. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  116. }
  117. %orig;
  118. }
  119. - (void)dealloc {
  120. %orig;
  121. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  122. }
  123. %new
  124. - (id)kaiCellForDevice {
  125. if(self && self.kaiCell == nil) {
  126. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self]; }
  127. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  128. [(KAIBatteryCell *)self.kaiCell updateInfo];
  129. return self.kaiCell;
  130. }
  131. %new
  132. - (void)resetKaiCellForNewPrefs {
  133. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self];
  134. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  135. [(KAIBatteryCell *)self.kaiCell updateInfo];
  136. }
  137. %end
  138. %hook KAICSTarget //Again, not a class
  139. - (void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
  140. if(hideChargingAnimation) {
  141. //Yeah bro this just makes the method never call to show the charging thing
  142. %orig(NO,NO,NO);
  143. }
  144. }
  145. - (void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { //might just be ios12
  146. if(hideChargingAnimation) {
  147. //Same idea
  148. %orig(NO,NO,NO,NO);
  149. }
  150. }
  151. %end
  152. %end
  153. %ctor {
  154. preferencesChanged();
  155. CFNotificationCenterAddObserver(
  156. CFNotificationCenterGetDarwinNotifyCenter(),
  157. &observer,
  158. (CFNotificationCallback)applyPrefs,
  159. kSettingsChangedNotification,
  160. NULL,
  161. CFNotificationSuspensionBehaviorDeliverImmediately
  162. );
  163. //Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
  164. mediaClass = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctItemView") class]) : ([objc_getClass("SBDashBoardAdjunctItemView") class]);
  165. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  166. Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSCoverSheetViewController") class]) : ([objc_getClass("SBDashBoardViewController") class]);
  167. if(enabled) {
  168. %init(main, Media = mediaClass, KAITarget = cls, KAICSTarget = CSCls); //BIG BRAIN BRO!!
  169. }
  170. NSLog(@"[kai]: loaded into %@", [NSBundle mainBundle].bundleIdentifier);
  171. }