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.

209 lines
7.1KB

  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. NSInteger lastSlot = [[self stackView].subviews count] -1;
  8. //this code is used to determine if kai is at the bottom of the stack view
  9. if([[self stackView].subviews objectAtIndex:lastSlot] != [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:lastSlot];
  14. } else if(!belowMusic && ![[self stackView].subviews containsObject:[KAIBatteryPlatter sharedInstance]]) {
  15. [[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  16. [[self stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
  17. }
  18. if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  19. [(NCNotificationListView *)(KAISelf.superview) fixComplicationsViewFrame];
  20. }
  21. [[KAIBatteryPlatter sharedInstance] calculateHeight];
  22. %orig;
  23. }
  24. -(void)setStackView:(UIStackView *)arg1 {
  25. if(!KAISelf.hasKai) {
  26. list = self;
  27. KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] initWithFrame:[self stackView].frame];
  28. //Add noti observer
  29. [[NSNotificationCenter defaultCenter] addObserver:self
  30. selector:@selector(KaiInfo)
  31. name:@"KaiInfoChanged"
  32. object:nil];
  33. KAISelf.hasKai = YES;
  34. if(![arg1.subviews containsObject:battery]) { //if not added
  35. //add kai to the stack view
  36. [arg1 addArrangedSubview:battery];
  37. }
  38. [battery updateBattery];
  39. //send the adjusted stackview as arg1
  40. %orig(arg1);
  41. }
  42. }
  43. %new
  44. -(void)KaiInfo {
  45. if(!isUpdating) {
  46. isUpdating = YES;
  47. //NSLog(@"kai: kai info will update");
  48. dispatch_async(dispatch_get_main_queue(), ^{
  49. [[KAIBatteryPlatter sharedInstance] updateBattery];
  50. if([KAIBatteryPlatter sharedInstance].number == 0) {
  51. [[KAIBatteryPlatter sharedInstance] removeFromSuperview];
  52. [[self stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  53. } else if(![[self stackView].subviews containsObject:[KAIBatteryPlatter sharedInstance]]) {
  54. [[self stackView] addSubview:[KAIBatteryPlatter sharedInstance]];
  55. [[self stackView] addArrangedSubview:[KAIBatteryPlatter sharedInstance]];
  56. }
  57. if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  58. [KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.35];
  59. //[KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.5];
  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. //if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)] && object == self && ([keyPath isEqualToString:@"charging"] || [keyPath isEqualToString:@"percentCharge"] || [keyPath isEqualToString:@"batterySaverModeActive"])) {
  81. //sends the noti to update battery info
  82. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  83. //}
  84. }
  85. %new
  86. -(id)kaiCellForDevice {
  87. if(self && self.kaiCell == nil) {
  88. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self]; }
  89. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  90. [(KAIBatteryCell *)self.kaiCell updateInfo];
  91. return self.kaiCell;
  92. }
  93. %new
  94. -(void)resetKaiCellForNewPrefs {
  95. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self];
  96. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  97. [(KAIBatteryCell *)self.kaiCell updateInfo];
  98. }
  99. %end
  100. %hook KAICSTarget //Again, not a class
  101. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
  102. if(hideChargingAnimation) {
  103. //Yeah bro this just makes the method never call to show the charging thing
  104. %orig(NO,NO,NO);
  105. }
  106. }
  107. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { //might just be ios12
  108. if(hideChargingAnimation) {
  109. //Same idea
  110. %orig(NO,NO,NO,NO);
  111. }
  112. }
  113. %end
  114. %end
  115. %group drm
  116. %hook SBIconController
  117. -(void)viewDidAppear:(BOOL)arg1 {
  118. %orig;
  119. UIAlertController* alert2 = [UIAlertController alertControllerWithTitle:@"kai"
  120. 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!"
  121. preferredStyle:UIAlertControllerStyleAlert];
  122. UIAlertAction* yes = [UIAlertAction actionWithTitle:@"I understand" style:UIAlertActionStyleDestructive
  123. handler:^(UIAlertAction * action) {
  124. }];
  125. [alert2 addAction:yes];
  126. [self presentViewController:alert2 animated:YES completion:nil];
  127. }
  128. %end
  129. %end
  130. %ctor {
  131. preferencesChanged();
  132. CFNotificationCenterAddObserver(
  133. CFNotificationCenterGetDarwinNotifyCenter(),
  134. &observer,
  135. (CFNotificationCallback)applyPrefs,
  136. kSettingsChangedNotification,
  137. NULL,
  138. CFNotificationSuspensionBehaviorDeliverImmediately
  139. );
  140. //Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
  141. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  142. Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSCoverSheetViewController") class]) : ([objc_getClass("SBDashBoardViewController") class]);
  143. //BOOL bypass = YES;
  144. BOOL bypass = NO;
  145. 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) {
  146. %init(main, KAITarget = cls, KAICSTarget = CSCls); //BIG BRAIN BRO!!
  147. } 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"])) {
  148. //if(0==1)
  149. %init(drm);
  150. }
  151. }