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.

139 lines
4.0KB

  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 "MobileGestalt.h"
  7. #import "NSTask.h"
  8. #define KAISelf ((CSAdjunctListView *)self) //for use when calling self in KAITarget
  9. //#define KAIBatteryStack UHDUEIHGCEBCHYDEICVKEVSAGJKBCXAHJGKVXHAS //lmao
  10. //#define KAIBatteryCell HDEIUOGEUBGUYOEXHNOPUSZIOJIGECEXIUSHXJXBE //very good
  11. @interface CSAdjunctListView : UIView
  12. @property (nonatomic, assign) BOOL hasKai;
  13. -(UIStackView *)stackView;
  14. -(void)setStackView:(UIStackView *)arg1;
  15. @end
  16. @interface CALayer (kai)
  17. @property (nonatomic, assign) BOOL continuousCorners;
  18. @end
  19. @interface SBIconController : UIViewController
  20. @end
  21. @interface SBCoverSheetPrimarySlidingViewController : UIViewController
  22. @end
  23. @interface UIDevice (kai)
  24. -(id)sf_udidString;
  25. -(id)_currentProduct;
  26. @end
  27. BOOL isUpdating = NO;
  28. //prefs
  29. BOOL enabled;
  30. BOOL disableGlyphs;
  31. BOOL hidePercent;
  32. BOOL showAll;
  33. BOOL belowMusic;
  34. BOOL hideDeviceLabel;
  35. BOOL hideChargingAnimation;
  36. BOOL showAllMinusInternal;
  37. NSInteger bannerStyle;
  38. NSInteger bannerAlign;
  39. NSInteger textColor;
  40. double spacing;
  41. double glyphSize;
  42. double bannerHeight;
  43. double cornerRadius;
  44. double bannerWidthFactor;
  45. double horizontalOffset;
  46. double bannerAlpha;
  47. //by importing here, I can use vars in the .mm files
  48. #import "KAIBatteryCell.mm"
  49. #import "KAIBatteryStack.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", 30);
  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. belowMusic = boolValueForKey(@"belowMusic", NO);
  100. hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
  101. textColor = numberForValue(@"textColor", 0);
  102. bannerAlpha = numberForValue(@"bannerAlpha", 1);
  103. showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO);
  104. if(disableGlyphs) {
  105. glyphSize = 0;
  106. }
  107. }
  108. static void applyPrefs()
  109. {
  110. preferencesChanged();
  111. isUpdating = YES;
  112. [[KAIBatteryStack sharedInstance] refreshForPrefs]; //so hard (not)
  113. isUpdating = NO;
  114. }