Device battery indicators on your Lock Screen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
6.8KB

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