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.

190 lines
6.4KB

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