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.

280 lines
11KB

  1. #include "KAIRootListController.h"
  2. KAIRootListController *controller;
  3. NSBundle *tweakBundle;
  4. //thank god for renai
  5. static inline NSString *getPackageVersion() {
  6. NSString *packageVersion = [NSString stringWithFormat:@"${%@}", @"Version"];
  7. int status;
  8. NSMutableArray<NSString *> *argsv0 = [NSMutableArray array];
  9. for (NSString *string in @[ @"/usr/bin/dpkg-query", @"-Wf", packageVersion, @"com.burritoz.kai" ]) {
  10. [argsv0
  11. addObject:[NSString stringWithFormat:@"'%@'",
  12. [string stringByReplacingOccurrencesOfString:@"'"
  13. withString:@"\\'"
  14. options:NSRegularExpressionSearch
  15. range:NSMakeRange(
  16. 0, string.length)]]];
  17. }
  18. NSString *argsv1 = [argsv0 componentsJoinedByString:@" "];
  19. FILE *file = popen(argsv1.UTF8String, "r");
  20. if (!file) {
  21. return nil;
  22. }
  23. char data[1024];
  24. NSMutableString *output = [NSMutableString string];
  25. while (fgets(data, 1024, file) != NULL) {
  26. [output appendString:[NSString stringWithUTF8String:data]];
  27. }
  28. int result = pclose(file);
  29. status = result;
  30. if (status == 0) {
  31. return output ?: @"🏴‍☠️ Pirated";
  32. }
  33. return @"🏴‍☠️ Pirated";
  34. }
  35. ////////
  36. static void respringNeeded() {
  37. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Respring"
  38. message:@"Changing this requires a respring for it to take effect. Would you like to respring now?"
  39. preferredStyle:UIAlertControllerStyleActionSheet];
  40. UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"No"
  41. style:UIAlertActionStyleCancel
  42. handler:^(UIAlertAction *action){
  43. }];
  44. UIAlertAction *yes = [UIAlertAction actionWithTitle:@"Respring"
  45. style:UIAlertActionStyleDestructive
  46. handler:^(UIAlertAction *action) {
  47. NSTask *t = [[NSTask alloc] init];
  48. [t setLaunchPath:@"usr/bin/killall"];
  49. [t setArguments:[NSArray arrayWithObjects:@"backboardd", nil]];
  50. [t launch];
  51. }];
  52. [alert addAction:defaultAction];
  53. [alert addAction:yes];
  54. [controller presentViewController:alert animated:YES completion:nil];
  55. }
  56. static void applyPrefs() {
  57. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("com.burritoz.kaiprefs/reload"), nil, nil, true);
  58. }
  59. @implementation KAIRootListController
  60. - (NSArray *)specifiers {
  61. if (!_specifiers) {
  62. _specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
  63. }
  64. return _specifiers;
  65. }
  66. - (void)viewWillAppear:(BOOL)arg1 {
  67. [[UISegmentedControl appearanceWhenContainedInInstancesOfClasses:@[ self.class ]] setTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]];
  68. [[UISwitch appearanceWhenContainedInInstancesOfClasses:@[ self.class ]] setOnTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]];
  69. [[UISlider appearanceWhenContainedInInstancesOfClasses:@[ self.class ]] setTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]];
  70. }
  71. - (void)viewWillDisappear:(BOOL)arg1 {
  72. [super viewWillDisappear:arg1];
  73. }
  74. - (void)viewDidLoad {
  75. [super viewDidLoad];
  76. self.navigationItem.titleView = [UIView new];
  77. self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
  78. self.titleLabel.font = [UIFont systemFontOfSize:17.5];
  79. self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  80. self.titleLabel.text = @"kai";
  81. self.titleLabel.alpha = 0.0;
  82. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  83. [self.navigationItem.titleView addSubview:self.titleLabel];
  84. self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
  85. self.iconView.contentMode = UIViewContentModeScaleAspectFit;
  86. self.iconView.image = [UIImage imageWithContentsOfFile:@"/Library/PreferenceBundles/kaiPrefs.bundle/icon.png"];
  87. self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
  88. self.iconView.alpha = 1.0;
  89. [self.navigationItem.titleView addSubview:self.iconView];
  90. [NSLayoutConstraint activateConstraints:@[
  91. [self.titleLabel.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor],
  92. [self.titleLabel.leadingAnchor constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor],
  93. [self.titleLabel.trailingAnchor constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor],
  94. [self.titleLabel.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor],
  95. [self.iconView.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor],
  96. [self.iconView.leadingAnchor constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor],
  97. [self.iconView.trailingAnchor constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor],
  98. [self.iconView.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor],
  99. ]];
  100. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Pirated :("
  101. message:@"Please install kai from Chariz repository."
  102. preferredStyle:UIAlertControllerStyleAlert];
  103. if ([[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/com.burritoz.kai.list"] && [[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/com.burritoz.kai.md5sums"]) {
  104. // nothing
  105. } else {
  106. [self presentViewController:alert animated:YES completion:nil];
  107. }
  108. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)respringNeeded, CFSTR("com.burritoz.kaiprefs.respringneeded"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
  109. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)applyPrefs, CFSTR("com.burritoz.kaiprefs.apply"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
  110. controller = self;
  111. }
  112. - (void)resetPrefs:(id)sender {
  113. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Reset Preferences"
  114. message:@"Are you sure you want to reset all of your preferences? This action CANNOT be undone! Your device will respring."
  115. preferredStyle:UIAlertControllerStyleAlert];
  116. UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"No"
  117. style:UIAlertActionStyleDefault
  118. handler:^(UIAlertAction *action){
  119. }];
  120. UIAlertAction *yes = [UIAlertAction actionWithTitle:@"Yes"
  121. style:UIAlertActionStyleDestructive
  122. handler:^(UIAlertAction *action) {
  123. NSUserDefaults *prefs = [[NSUserDefaults standardUserDefaults] init];
  124. [prefs removePersistentDomainForName:@"com.burritoz.kaiprefs"];
  125. NSTask *f = [[NSTask alloc] init];
  126. [f setLaunchPath:@"/usr/bin/killall"];
  127. [f setArguments:[NSArray arrayWithObjects:@"backboardd", nil]];
  128. [f launch];
  129. }];
  130. [alert addAction:defaultAction];
  131. [alert addAction:yes];
  132. [self presentViewController:alert animated:YES completion:nil];
  133. }
  134. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  135. CGFloat offsetY = scrollView.contentOffset.y;
  136. if (offsetY > 120) {
  137. [UIView animateWithDuration:0.2
  138. animations:^{
  139. self.iconView.alpha = 1.0;
  140. self.titleLabel.alpha = 0.0;
  141. }];
  142. } else {
  143. [UIView animateWithDuration:0.2
  144. animations:^{
  145. self.iconView.alpha = 0.0;
  146. self.titleLabel.alpha = 1.0;
  147. }];
  148. }
  149. }
  150. - (void)followMeBurritoz {
  151. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/burrit0ztweaks"]];
  152. }
  153. - (void)followMeOnTwitterThomz {
  154. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/thomzi07"]];
  155. }
  156. @end
  157. @implementation KaiHeaderCell // Header Cell
  158. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(id)reuseIdentifier specifier:(id)specifier {
  159. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier];
  160. if (self) {
  161. UILabel *tweakLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, self.contentView.bounds.size.width + 30, 50)];
  162. [tweakLabel setTextAlignment:NSTextAlignmentLeft];
  163. [tweakLabel setFont:[UIFont systemFontOfSize:50 weight:UIFontWeightRegular]];
  164. tweakLabel.text = @"kai";
  165. UILabel *devLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, self.contentView.bounds.size.width + 30, 50)];
  166. [devLabel setTextAlignment:NSTextAlignmentLeft];
  167. [devLabel setFont:[UIFont systemFontOfSize:20 weight:UIFontWeightMedium]];
  168. devLabel.alpha = 0.8;
  169. devLabel.text = getPackageVersion();
  170. NSBundle *bundle = [[NSBundle alloc] initWithPath:@"/Library/PreferenceBundles/kaiPrefs.bundle"];
  171. UIImage *logo = [UIImage imageWithContentsOfFile:[bundle pathForResource:@"iconFullSize" ofType:@"png"]];
  172. UIImageView *icon = [[UIImageView alloc] initWithImage:logo];
  173. icon.frame = CGRectMake(self.contentView.bounds.size.width - 35, 35, 70, 70);
  174. icon.translatesAutoresizingMaskIntoConstraints = NO;
  175. [self addSubview:tweakLabel];
  176. [self addSubview:devLabel];
  177. [self addSubview:icon];
  178. [icon.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:-20].active = YES;
  179. [icon.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
  180. [icon.widthAnchor constraintEqualToConstant:70].active = YES;
  181. [icon.heightAnchor constraintEqualToConstant:70].active = YES;
  182. icon.layer.masksToBounds = YES;
  183. icon.layer.cornerRadius = 15;
  184. }
  185. return self;
  186. }
  187. - (instancetype)initWithSpecifier:(PSSpecifier *)specifier {
  188. return [self initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"KaiHeaderCell" specifier:specifier];
  189. }
  190. - (void)setFrame:(CGRect)frame {
  191. frame.origin.x = 0;
  192. [super setFrame:frame];
  193. }
  194. - (CGFloat)preferredHeightForWidth:(CGFloat)arg1 {
  195. return 140.0f;
  196. }
  197. @end
  198. @implementation Thomz_TwitterCell // lil copy of HBTwitterCell from Cephei
  199. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
  200. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier];
  201. if (self) {
  202. UILabel *User = [[UILabel alloc] initWithFrame:CGRectMake(70, 15, 200, 20)];
  203. [User setText:specifier.properties[@"user"]];
  204. [User setFont:[User.font fontWithSize:15]];
  205. UILabel *Description = [[UILabel alloc] initWithFrame:CGRectMake(70, 35, 200, 20)];
  206. [Description setText:specifier.properties[@"description"]];
  207. [Description setFont:[Description.font fontWithSize:10]];
  208. NSBundle *bundle = [[NSBundle alloc] initWithPath:@"/Library/PreferenceBundles/kaiPrefs.bundle"];
  209. UIImage *profilePicture;
  210. profilePicture = [UIImage imageWithContentsOfFile:[bundle pathForResource:specifier.properties[@"image"] ofType:@"jpg"]];
  211. UIImageView *profilePictureView = [[UIImageView alloc] initWithImage:profilePicture];
  212. [profilePictureView.layer setMasksToBounds:YES];
  213. [profilePictureView.layer setCornerRadius:20];
  214. [profilePictureView setFrame:CGRectMake(15, 15, 40, 40)];
  215. [self addSubview:User];
  216. [self addSubview:Description];
  217. [self addSubview:profilePictureView];
  218. }
  219. return self;
  220. }
  221. @end