Device battery indicators on your Lock Screen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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