Device battery indicators on your Lock Screen
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

205 líneas
7.0KB

  1. #import "Kai.h"
  2. %group main
  3. %hook KAITarget //This class is defined in %ctor, KAITarget is not a class name.
  4. %property (nonatomic, assign) BOOL hasKai;
  5. -(void)_layoutStackView {
  6. NSInteger lastSlot = [[self stackView].subviews count] -1;
  7. //this code is used to determine if kai is at the bottom of the stack view
  8. if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBatteryPlatter sharedInstance] && belowMusic) {
  9. //if it is not, but the option to have kai below music is on, i simply remove from it's current pos.
  10. //and insert into last slot.
  11. [[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  12. [[self stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:lastSlot];
  13. }
  14. if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  15. [(NCNotificationListView *)(KAISelf.superview) fixComplicationsViewFrame];
  16. }
  17. [[KAIBatteryPlatter sharedInstance] calculateHeight];
  18. %orig;
  19. }
  20. -(void)removeArrangedSubview:(id)arg1 {
  21. %orig;
  22. [[KAIBatteryPlatter sharedInstance] calculateHeight];
  23. }
  24. -(void)addArrangedSubview:(id)arg1 {
  25. %orig;
  26. [[KAIBatteryPlatter sharedInstance] calculateHeight];
  27. }
  28. -(void)setStackView:(UIStackView *)arg1 {
  29. if(!KAISelf.hasKai) {
  30. KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] initWithFrame:[self stackView].frame];
  31. //Add noti observer
  32. [[NSNotificationCenter defaultCenter] addObserver:self
  33. selector:@selector(KaiInfo)
  34. name:@"KaiInfoChanged"
  35. object:nil];
  36. KAISelf.hasKai = YES;
  37. if(![arg1.subviews containsObject:battery]) { //if not added
  38. //add kai to the stack view
  39. [arg1 addArrangedSubview:battery];
  40. }
  41. [battery updateBattery];
  42. //send the adjusted stackview as arg1
  43. %orig(arg1);
  44. }
  45. }
  46. %new
  47. -(void)KaiInfo {
  48. if(!isUpdating) {
  49. isUpdating = YES;
  50. //NSLog(@"kai: kai info will update");
  51. dispatch_async(dispatch_get_main_queue(), ^{
  52. [[KAIBatteryPlatter sharedInstance] updateBattery];
  53. if([KAIBatteryPlatter sharedInstance].number == 0) {
  54. [[KAIBatteryPlatter sharedInstance] removeFromSuperview];
  55. [[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  56. } else if(![[self stackView].subviews containsObject:[KAIBatteryPlatter sharedInstance]]) {
  57. [[self stackView] addSubview:[KAIBatteryPlatter sharedInstance]];
  58. [[self stackView] addArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  59. }
  60. if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  61. [KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.35];
  62. //[KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.5];
  63. }
  64. isUpdating = NO;
  65. });
  66. }
  67. }
  68. %end
  69. %hook BCBatteryDevice
  70. %property (nonatomic, strong) KAIBatteryCell *kaiCell;
  71. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  72. //Posts a notification to self when these keys change
  73. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  74. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  75. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  76. return %orig;
  77. }
  78. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  79. //if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)] && object == self && ([keyPath isEqualToString:@"charging"] || [keyPath isEqualToString:@"percentCharge"] || [keyPath isEqualToString:@"batterySaverModeActive"])) {
  80. //sends the noti to update battery info
  81. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  82. //}
  83. }
  84. %new
  85. -(id)kaiCellForDevice {
  86. if(self && self.kaiCell == nil) {
  87. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self]; }
  88. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  89. [(KAIBatteryCell *)self.kaiCell updateInfo];
  90. return self.kaiCell;
  91. }
  92. %new
  93. -(void)resetKaiCellForNewPrefs {
  94. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self];
  95. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  96. [(KAIBatteryCell *)self.kaiCell updateInfo];
  97. }
  98. %end
  99. %hook KAICSTarget //Again, not a class
  100. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
  101. if(hideChargingAnimation) {
  102. //Yeah bro this just makes the method never call to show the charging thing
  103. %orig(NO,NO,NO);
  104. }
  105. }
  106. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { //might just be ios12
  107. if(hideChargingAnimation) {
  108. //Same idea
  109. %orig(NO,NO,NO,NO);
  110. }
  111. }
  112. %end
  113. %end
  114. %group drm
  115. %hook SBIconController
  116. -(void)viewDidAppear:(BOOL)arg1 {
  117. %orig;
  118. UIAlertController* alert2 = [UIAlertController alertControllerWithTitle:@"kai"
  119. message:@"Woops! Chariz is saying your device has not purchased Multipla! You must have purchased Multipla to use the kai beta. Please make sure to link your device to your Chariz account!"
  120. preferredStyle:UIAlertControllerStyleAlert];
  121. UIAlertAction* yes = [UIAlertAction actionWithTitle:@"I understand" style:UIAlertActionStyleDestructive
  122. handler:^(UIAlertAction * action) {
  123. }];
  124. [alert2 addAction:yes];
  125. [self presentViewController:alert2 animated:YES completion:nil];
  126. }
  127. %end
  128. %end
  129. %ctor {
  130. preferencesChanged();
  131. CFNotificationCenterAddObserver(
  132. CFNotificationCenterGetDarwinNotifyCenter(),
  133. &observer,
  134. (CFNotificationCallback)applyPrefs,
  135. kSettingsChangedNotification,
  136. NULL,
  137. CFNotificationSuspensionBehaviorDeliverImmediately
  138. );
  139. //Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
  140. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  141. Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSCoverSheetViewController") class]) : ([objc_getClass("SBDashBoardViewController") class]);
  142. //BOOL bypass = YES;
  143. BOOL bypass = NO;
  144. if(([[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.list"] && [[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.md5sums"]) || bypass) {
  145. %init(main, KAITarget = cls, KAICSTarget = CSCls); //BIG BRAIN BRO!!
  146. } else if(!bypass && !([[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.list"] && [[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.md5sums"])) {
  147. //if(0==1)
  148. %init(drm);
  149. }
  150. }