Device battery indicators on your Lock Screen
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

187 lines
6.2KB

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