Device battery indicators on your Lock Screen
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

128 lines
3.9KB

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