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.

189 lines
6.3KB

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