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.

192 lines
6.5KB

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