Device battery indicators on your Lock Screen
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

131 lines
3.2KB

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