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.

199 lines
6.9KB

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