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ů.

155 lines
3.5KB

  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 CSMainPageView : UIView
  12. @property (nonatomic, strong) KAIBattery *battery;
  13. -(void)KaiUpdate;
  14. @end
  15. @interface SBCoverSheetPrimarySlidingViewController
  16. -(void)KaiUpdate;
  17. @end
  18. @interface _CSSingleBatteryChargingView : UIView
  19. @end
  20. BOOL setFrame = NO;
  21. CSMainPageView *batteryWidget;
  22. CGRect original;
  23. CGRect originalBattery;
  24. /*
  25. - (void)addObserver:(NSObject *)observer
  26. forKeyPath:(NSString *)keyPath
  27. options:(NSKeyValueObservingOptions)options
  28. context:(void *)context*/
  29. /*
  30. %hook BCBatterDeviceController
  31. +(id)sharedInstance {
  32. [%orig addObserver:self forKeyPath:@"sortedDevices" options:NSKeyValueObservingOptionNew context:nil];
  33. return %orig;
  34. }
  35. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  36. if ([keyPath isEqualToString:@"sortedDevices"]) {
  37. [[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.weather" suspended:NO];
  38. }
  39. }
  40. %end*/
  41. %hook SBCoverSheetPrimarySlidingViewController
  42. -(void)viewWillAppear:(BOOL)arg1 {
  43. %orig;
  44. [[NSNotificationCenter defaultCenter] addObserver:self
  45. selector:@selector(KaiUpdate)
  46. name:@"KaiInfoChanged"
  47. object:nil];
  48. }
  49. %new
  50. -(void)KaiUpdate {
  51. [batteryWidget.battery updateBattery];
  52. [batteryWidget KaiUpdate];
  53. }
  54. /*
  55. -(void)viewWillDisappear:(BOOL)arg1 {
  56. %orig;
  57. [batteryWidget.battery updateBattery];
  58. [batteryWidget KaiUpdate];
  59. }*/
  60. %end
  61. %hook CSMainPageView
  62. %property (nonatomic, strong) KAIBattery *battery;
  63. -(void)updateForPresentation:(id)arg1 {
  64. %orig;
  65. if(!setFrame) {
  66. original = self.frame;
  67. self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, self.frame.origin.y + 150, self.frame.size.width - 16, self.frame.size.height)];
  68. originalBattery = self.battery.frame;
  69. [self addSubview:self.battery];
  70. setFrame = YES;
  71. batteryWidget = self;
  72. }
  73. [self KaiUpdate];
  74. }
  75. %new
  76. -(void)KaiUpdate {
  77. [UIView animateWithDuration:0.3 animations:^{
  78. self.frame = CGRectMake(
  79. original.origin.x,
  80. original.origin.y + (self.battery.number * 85),
  81. original.size.width,
  82. original.size.height
  83. );
  84. self.battery.frame = CGRectMake(
  85. originalBattery.origin.x,
  86. originalBattery.origin.y - (self.battery.number * 85) + 85,
  87. originalBattery.size.width,
  88. originalBattery.size.height
  89. );
  90. }];
  91. }
  92. %end
  93. %hook BCBatteryDevice
  94. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  95. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  96. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  97. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  98. return %orig;
  99. }
  100. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  101. dispatch_async(dispatch_get_main_queue(), ^{
  102. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  103. });
  104. }
  105. %end
  106. %hook _CSSingleBatteryChargingView
  107. -(void)initWithFrame:(CGRect)arg1 {
  108. %orig;
  109. [self removeFromSuperview];
  110. }
  111. -(CGFloat)desiredVisibilityDuration {
  112. return 0;
  113. }
  114. -(void)setBatteryVisible:(BOOL)arg1 {
  115. %orig(NO);
  116. }
  117. %end