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.

360 lines
13KB

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