Device battery indicators on your Lock Screen
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

143 linhas
4.1KB

  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. #define KAISelf ((CSAdjunctListView *)self)
  7. @interface UIApplication (Kai)
  8. +(id)sharedApplication;
  9. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  10. @end
  11. @interface CSAdjunctListView : UIView
  12. @property (nonatomic, assign) BOOL hasKai;
  13. -(UIStackView *)stackView;
  14. -(void)setStackView:(UIStackView *)arg1;
  15. -(void)KaiUpdate;
  16. @end
  17. @interface SBDashBoardAdjunctListView : UIView
  18. @property (nonatomic, assign) BOOL hasKai;
  19. -(UIStackView *)stackView;
  20. -(void)setStackView:(UIStackView *)arg1;
  21. -(void)KaiUpdate;
  22. @end
  23. @interface CSMainPageView : UIView
  24. -(void)updateForPresentation:(id)arg1;
  25. @end
  26. @interface _CSSingleBatteryChargingView : UIView
  27. @end
  28. @interface NSLayoutConstraint (Kai)
  29. +(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ;
  30. @end
  31. @interface CALayer (kai)
  32. @property (nonatomic, assign) BOOL continuousCorners;
  33. @end
  34. BOOL isUpdating = NO;
  35. //prefs
  36. BOOL enabled;
  37. BOOL disableGlyphs;
  38. BOOL hidePercent;
  39. BOOL showAll;
  40. BOOL hideDeviceLabel;
  41. NSInteger bannerStyle;
  42. NSInteger bannerAlign;
  43. double spacing;
  44. double glyphSize;
  45. double bannerHeight;
  46. double cornerRadius;
  47. double bannerWidthFactor;
  48. double horizontalOffset;
  49. #import "KAIBattery.mm"
  50. #define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist"
  51. #define kIdentifier @"com.burritoz.kaiprefs"
  52. #define kSettingsChangedNotification (CFStringRef)@"com.burritoz.kaiprefs/reload"
  53. #define kSettingsPath @"/var/mobile/Library/Preferences/com.burritoz.kaiprefs.plist"
  54. NSDictionary *prefs = nil;
  55. static void *observer = NULL;
  56. static void reloadPrefs()
  57. {
  58. if ([NSHomeDirectory() isEqualToString:@"/var/mobile"])
  59. {
  60. CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  61. if (keyList)
  62. {
  63. prefs = (NSDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
  64. if (!prefs)
  65. {
  66. prefs = [NSDictionary new];
  67. }
  68. CFRelease(keyList);
  69. }
  70. }
  71. else
  72. {
  73. prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
  74. }
  75. }
  76. static BOOL boolValueForKey(NSString *key, BOOL defaultValue) {
  77. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] boolValue] : defaultValue);
  78. }
  79. static double numberForValue(NSString *key, double defaultValue) {
  80. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue);
  81. }
  82. static void preferencesChanged()
  83. {
  84. CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
  85. reloadPrefs();
  86. enabled = boolValueForKey(@"enabled", YES);
  87. spacing = numberForValue(@"spacing", 5);
  88. glyphSize = numberForValue(@"glyphSize", 35);
  89. bannerHeight = numberForValue(@"bannerHeight", 80);
  90. cornerRadius = numberForValue(@"cornerRadius", 13);
  91. disableGlyphs = boolValueForKey(@"disableGlyphs", NO);
  92. hidePercent = boolValueForKey(@"hidePercent", NO);
  93. bannerStyle = numberForValue(@"bannerStyle", 1);
  94. showAll = boolValueForKey(@"showAll", NO);
  95. bannerWidthFactor = numberForValue(@"bannerWidthFactor", 0);
  96. hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO);
  97. bannerAlign = numberForValue(@"bannerAlign", 2);
  98. horizontalOffset = numberForValue(@"horizontalOffset", 0);
  99. if(disableGlyphs) {
  100. glyphSize = 0;
  101. }
  102. }
  103. static void applyPrefs()
  104. {
  105. preferencesChanged();
  106. isUpdating = YES;
  107. [UIView animateWithDuration:0.3 animations:^{
  108. [KAIBattery sharedInstance].alpha = 0;
  109. } completion:^(BOOL finished){
  110. [[KAIBattery sharedInstance] updateBattery];
  111. [(CSAdjunctListView *)([KAIBattery sharedInstance].superview.superview) KaiUpdate];
  112. [UIView animateWithDuration:0.35 animations:^{
  113. [KAIBattery sharedInstance].alpha = 1;
  114. } completion:^(BOOL finished){
  115. isUpdating = NO;
  116. }];
  117. }];
  118. }