Device battery indicators on your Lock Screen
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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