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.

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