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.

200 lines
4.4KB

  1. #include <CoreFoundation/CoreFoundation.h>
  2. #import <Foundation/Foundation.h>
  3. #include <stdio.h>
  4. #import <objc/runtime.h>
  5. #import <UIKit/UIKit.h>
  6. #import "KAIBattery.mm"
  7. @interface UIApplication (Kai)
  8. +(id)sharedApplication;
  9. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  10. @end
  11. @interface CSCoverSheetViewBase : UIView
  12. @property (nonatomic, strong) KAIBattery *battery;
  13. -(void)KaiUpdate;
  14. -(void)KaiInit;
  15. @end
  16. @interface SBCoverSheetPrimarySlidingViewController
  17. -(void)KaiUpdate;
  18. @end
  19. @interface CSMainPageView : UIView
  20. -(void)updateForPresentation:(id)arg1;
  21. @end
  22. @interface _CSSingleBatteryChargingView : UIView
  23. @end
  24. BOOL setFrame = NO;
  25. UIView *batteryWidgetController;
  26. KAIBattery *batteryWidget;
  27. CSCoverSheetViewBase *base;
  28. CGRect original;
  29. CGRect originalBattery;
  30. /*
  31. - (void)addObserver:(NSObject *)observer
  32. forKeyPath:(NSString *)keyPath
  33. options:(NSKeyValueObservingOptions)options
  34. context:(void *)context*/
  35. /*
  36. %hook BCBatterDeviceController
  37. +(id)sharedInstance {
  38. [%orig addObserver:self forKeyPath:@"sortedDevices" options:NSKeyValueObservingOptionNew context:nil];
  39. return %orig;
  40. }
  41. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  42. if ([keyPath isEqualToString:@"sortedDevices"]) {
  43. [[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.weather" suspended:NO];
  44. }
  45. }
  46. %end*/
  47. %hook CSMainPageView
  48. -(void)updateForPresentation:(id)arg1 {
  49. if(!setFrame) {
  50. if([self.subviews count] > 0) {
  51. CSCoverSheetViewBase *base = [self.subviews objectAtIndex:0];
  52. [base KaiInit];
  53. }
  54. }
  55. [base KaiUpdate];
  56. }
  57. %end
  58. %hook SBCoverSheetPrimarySlidingViewController
  59. -(void)viewWillAppear:(BOOL)arg1 {
  60. %orig;
  61. [[NSNotificationCenter defaultCenter] addObserver:self
  62. selector:@selector(KaiUpdate)
  63. name:@"KaiInfoChanged"
  64. object:nil];
  65. [self KaiUpdate];
  66. }
  67. %new
  68. -(void)KaiUpdate {
  69. [batteryWidget updateBattery];
  70. [base KaiUpdate];
  71. }
  72. %end
  73. %hook CSCoverSheetViewBase
  74. %property (nonatomic, strong) KAIBattery *battery;
  75. -(void)traitCollectionDidChange:(id)arg1 {
  76. %orig;
  77. [batteryWidget darkLightMode];
  78. }
  79. -(void)setNeedsLayout {
  80. %orig;
  81. [self KaiUpdate];
  82. }
  83. %new
  84. -(void)KaiInit {
  85. if(!setFrame) {
  86. UIView *scroller;
  87. if([self.subviews count] > 1) {
  88. UIView *temp = [self.subviews objectAtIndex:1];
  89. if([temp.subviews count] > 0) {
  90. scroller = [temp.subviews objectAtIndex:0];
  91. base = self;
  92. }
  93. }
  94. /*UIView *notiView;
  95. if([self.subviews count] > 0) {
  96. notiView = [self.subviews objectAtIndex:0];
  97. }*/
  98. original = scroller.frame;
  99. KAIBattery *battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, 0, self.frame.size.width - 16, self.frame.size.height)];
  100. originalBattery = battery.frame;
  101. [scroller addSubview:battery];
  102. setFrame = YES;
  103. batteryWidgetController = scroller;
  104. batteryWidget = battery;
  105. }
  106. [self KaiUpdate];
  107. [batteryWidget darkLightMode];
  108. }
  109. %new
  110. -(void)KaiUpdate {
  111. [UIView animateWithDuration:0.3 animations:^{
  112. /*UIView *notiView;
  113. if([self.subviews count] > 0) {
  114. notiView = [self.subviews objectAtIndex:0];
  115. }*/
  116. batteryWidgetController.frame = CGRectMake(
  117. original.origin.x,
  118. original.origin.y + (batteryWidget.number * 85),
  119. original.size.width,
  120. original.size.height
  121. );
  122. batteryWidget.frame = CGRectMake(
  123. originalBattery.origin.x,
  124. originalBattery.origin.y - (batteryWidget.number * 85),
  125. originalBattery.size.width,
  126. originalBattery.size.height
  127. );
  128. }];
  129. [batteryWidget darkLightMode];
  130. }
  131. %end
  132. %hook BCBatteryDevice
  133. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  134. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  135. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  136. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  137. return %orig;
  138. }
  139. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  140. dispatch_async(dispatch_get_main_queue(), ^{
  141. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  142. });
  143. }
  144. %end
  145. %hook _CSSingleBatteryChargingView
  146. -(void)initWithFrame:(CGRect)arg1 {
  147. %orig;
  148. [self removeFromSuperview];
  149. }
  150. -(CGFloat)desiredVisibilityDuration {
  151. return 0;
  152. }
  153. -(void)setBatteryVisible:(BOOL)arg1 {
  154. %orig(NO);
  155. }
  156. %end