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.

205 lines
6.7KB

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