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.

687 lines
21KB

  1. #import "Reddit.h"
  2. #import "assets/TFHelper.h"
  3. static BOOL isEnabled;
  4. static BOOL isRedditEnabled;
  5. static BOOL isTFDeletedOnly;
  6. static CGFloat pushshiftRequestTimeoutValue;
  7. int firstVersionPart = 2020;
  8. int secondVersionPart = 0;
  9. %group Reddit_v4_current
  10. %hook CommentTreeNode
  11. %property(assign,nonatomic)id commentTreeHeaderNode;
  12. %property(assign,nonatomic)id commentTreeCommandBarNode;
  13. %end
  14. %hook CommentTreeHeaderView
  15. - (void)layoutSubviews {
  16. %orig;
  17. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  18. }
  19. %end
  20. %hook CommentTreeHeaderNode
  21. - (void)didLoad {
  22. %orig;
  23. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  24. }
  25. %end
  26. %hook CommentTreeCommandBarNode
  27. - (void)didLoad {
  28. %orig;
  29. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  30. }
  31. %end
  32. %hook CommentActionSheetViewController
  33. - (void)setItems:(id)arg1 {
  34. NSString *author = [[self comment] author];
  35. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  36. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  37. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  38. CGFloat scale = origImage.size.width / existingImageSize.width;
  39. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  40. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  41. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  42. [undeleteItem release];
  43. }
  44. %orig;
  45. }
  46. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  47. %orig;
  48. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  49. [self dismissViewControllerAnimated:YES completion:nil];
  50. id commentTreeNode = [self commentTreeNode];
  51. Comment *comment = [commentTreeNode comment];
  52. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  53. }
  54. }
  55. %new
  56. - (void)completeUndeleteCommentAction:(NSDictionary *)data {
  57. id commentTreeNode = [self commentTreeNode];
  58. Comment *comment = [commentTreeNode comment];
  59. NSString *author = data[@"author"];
  60. NSString *body = data[@"body"];
  61. NSMutableAttributedString *bodyMutableAttributedText;
  62. id themeManager;
  63. id isNightMode;
  64. id textColor;
  65. if (firstVersionPart == 2020) {
  66. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  67. AppSettings *appSettings = [%c(AppSettings) sharedSettings];
  68. AccountManager *accountManager = secondVersionPart >= 29 ? [appDelegate accountManager] : [%c(AccountManager) sharedManager];
  69. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:appSettings];
  70. isNightMode = [[accountManager defaults] objectForKey:@"kUseNightKey"];
  71. if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0") && [appSettings isAutoDarkModeEnabled]) {
  72. NSInteger sysInterfaceStyle = [[UITraitCollection _currentTraitCollection] userInterfaceStyle];
  73. if (sysInterfaceStyle == UIUserInterfaceStyleDark){
  74. textColor = [[themeManager darkTheme] bodyTextColor];
  75. } else {
  76. textColor = [[themeManager lightTheme] bodyTextColor];
  77. }
  78. } else {
  79. if (isNightMode) {
  80. textColor = [[themeManager darkTheme] bodyTextColor];
  81. } else {
  82. textColor = [[themeManager lightTheme] bodyTextColor];
  83. }
  84. }
  85. [themeManager release];
  86. } else {
  87. if (secondVersionPart >= 45) {
  88. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  89. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  90. if (isNightMode) {
  91. textColor = [[themeManager darkTheme] bodyTextColor];
  92. } else {
  93. textColor = [[themeManager lightTheme] bodyTextColor];
  94. }
  95. [themeManager release];
  96. } else if (secondVersionPart >= 37) {
  97. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  98. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  99. if (isNightMode) {
  100. textColor = [[themeManager nightTheme] bodyTextColor];
  101. } else {
  102. textColor = [[themeManager dayTheme] bodyTextColor];
  103. }
  104. [themeManager release];
  105. } else {
  106. themeManager = [%c(ThemeManager) sharedManager];
  107. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  108. if (isNightMode) {
  109. textColor = [[themeManager nightTheme] bodyTextColor];
  110. } else {
  111. textColor = [[themeManager dayTheme] bodyTextColor];
  112. }
  113. }
  114. }
  115. bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  116. [bodyMutableAttributedText beginEditing];
  117. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  118. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  119. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  120. }];
  121. [bodyMutableAttributedText endEditing];
  122. [comment setAuthor:author];
  123. [comment setBodyText:body];
  124. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  125. [comment setBodyAttributedText:bodyMutableAttributedText];
  126. [[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
  127. [bodyMutableAttributedText release];
  128. }
  129. %end
  130. %hook PostDetailViewController
  131. %property(strong,nonatomic) id feedPostTextWithThumbnailNode;
  132. %property(strong,nonatomic) id feedPostDetailCellNode;
  133. %end
  134. %hook FeedPostDetailCellNode
  135. - (void)didLoad {
  136. %orig;
  137. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  138. }
  139. %end
  140. %hook PostActionSheetViewController
  141. - (void)setItems:(id)arg1 {
  142. Post *post = [self post];
  143. NSString *author = [post author];
  144. if ([post isSelfPost]) {
  145. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  146. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  147. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  148. CGFloat scale = origImage.size.width / existingImageSize.width;
  149. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  150. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  151. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  152. [undeleteItem release];
  153. }
  154. }
  155. %orig;
  156. }
  157. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  158. %orig;
  159. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  160. [self dismissViewControllerAnimated:YES completion:nil];
  161. Post *post = [self post];
  162. if ([post isSelfPost]){
  163. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  164. }
  165. }
  166. }
  167. %new
  168. - (void)completeUndeletePostAction:(NSDictionary *)data {
  169. Post *post = [self post];
  170. NSString *author = data[@"author"];
  171. NSString *body = data[@"body"];
  172. id themeManager;
  173. id isNightMode;
  174. id textColor;
  175. if (firstVersionPart == 2020) {
  176. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  177. AccountManager *accountManager = secondVersionPart >= 29 ? [appDelegate accountManager] : [%c(AccountManager) sharedManager];
  178. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  179. isNightMode = [[accountManager defaults] objectForKey:@"kUseNightKey"];
  180. if (isNightMode) {
  181. textColor = [[themeManager darkTheme] bodyTextColor];
  182. } else {
  183. textColor = [[themeManager lightTheme] bodyTextColor];
  184. }
  185. [themeManager release];
  186. } else {
  187. if (secondVersionPart >= 45) {
  188. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  189. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  190. if (isNightMode) {
  191. textColor = [[themeManager darkTheme] bodyTextColor];
  192. } else {
  193. textColor = [[themeManager lightTheme] bodyTextColor];
  194. }
  195. [themeManager release];
  196. } else if (secondVersionPart >= 37) {
  197. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  198. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  199. if (isNightMode) {
  200. textColor = [[themeManager nightTheme] bodyTextColor];
  201. } else {
  202. textColor = [[themeManager dayTheme] bodyTextColor];
  203. }
  204. [themeManager release];
  205. } else {
  206. themeManager = [%c(ThemeManager) sharedManager];
  207. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  208. if (isNightMode) {
  209. textColor = [[themeManager nightTheme] bodyTextColor];
  210. } else {
  211. textColor = [[themeManager dayTheme] bodyTextColor];
  212. }
  213. }
  214. }
  215. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  216. [bodyMutableAttributedText beginEditing];
  217. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  218. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  219. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  220. }];
  221. [bodyMutableAttributedText endEditing];
  222. [post setSelfText:body];
  223. [post setAuthor:author];
  224. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  225. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  226. if (firstVersionPart == 2020) {
  227. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  228. } else {
  229. if (secondVersionPart >= 44) {
  230. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  231. } else if (secondVersionPart >= 38) {
  232. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  233. } else {
  234. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  235. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
  236. }
  237. }
  238. [bodyMutableAttributedText release];
  239. }
  240. %end
  241. %end
  242. %group Reddit_v4_ios10
  243. %hook CommentsViewController
  244. %new
  245. - (void)updateComments {
  246. [self reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  247. }
  248. %new
  249. - (void)updatePostText {
  250. if (secondVersionPart >= 2){
  251. [self reloadPostSection:YES];
  252. } else {
  253. [self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
  254. }
  255. }
  256. %end
  257. %hook CommentActionSheetViewController
  258. - (void)setItems:(id)arg1 {
  259. NSString *author = [[self comment] author];
  260. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  261. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  262. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  263. CGFloat scale = origImage.size.width / existingImageSize.width;
  264. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  265. id undeleteItem;
  266. if (secondVersionPart >= 18) {
  267. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  268. } else {
  269. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  270. }
  271. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  272. [undeleteItem release];
  273. }
  274. %orig;
  275. }
  276. // >= 4.21
  277. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  278. %orig;
  279. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  280. [self dismissViewControllerAnimated:YES completion:nil];
  281. Comment *comment = [self comment];
  282. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  283. }
  284. }
  285. // <= 4.20
  286. - (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
  287. %orig;
  288. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  289. [self dismissViewControllerAnimated:YES completion:nil];
  290. Comment *comment = [self comment];
  291. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  292. }
  293. }
  294. %new
  295. - (void)completeUndeleteCommentAction:(NSDictionary *)data {
  296. Comment *comment = [self comment];
  297. NSString *body = data[@"body"];
  298. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  299. [comment setAuthor:data[@"author"]];
  300. [comment setBodyText:body];
  301. [comment setBodyAttributedText:bodyMutableAttributedText];
  302. if (secondVersionPart >= 12) {
  303. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  304. }
  305. [[self commentActionSheetDelegate] updateComments];
  306. [bodyMutableAttributedText release];
  307. }
  308. %end
  309. %hook PostActionSheetViewController
  310. - (void)setItems:(id)arg1{
  311. Post *post = [self post];
  312. NSString *author = [post author];
  313. if ([post isSelfPost]) {
  314. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  315. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  316. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  317. CGFloat scale = origImage.size.width / existingImageSize.width;
  318. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  319. id undeleteItem;
  320. if (secondVersionPart >= 18) {
  321. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  322. } else {
  323. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  324. }
  325. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  326. [undeleteItem release];
  327. }
  328. }
  329. %orig;
  330. }
  331. // >= 4.21
  332. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  333. %orig;
  334. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  335. [self dismissViewControllerAnimated:YES completion:nil];
  336. Post *post = [self post];
  337. if ([post isSelfPost]) {
  338. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  339. }
  340. }
  341. }
  342. // <= 4.20
  343. - (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
  344. %orig;
  345. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  346. [self dismissViewControllerAnimated:YES completion:nil];
  347. Post *post = [self post];
  348. if ([post isSelfPost]){
  349. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  350. }
  351. }
  352. }
  353. %new
  354. - (void)completeUndeletePostAction:(NSDictionary *)data {
  355. Post *post = [self post];
  356. NSString *body = data[@"body"];
  357. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  358. [post setAuthor:data[@"author"]];
  359. [post setSelfText:body];
  360. [post setSelfTextAttributed:bodyMutableAttributedText];
  361. if (secondVersionPart >= 8) {
  362. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  363. }
  364. if (secondVersionPart >= 15) {
  365. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  366. }
  367. [[self postActionSheetDelegate] updatePostText];
  368. [bodyMutableAttributedText release];
  369. }
  370. %end
  371. %end
  372. //outdated and unchanged from first version of this tweak...
  373. //TODO: move button to menu, add post support, make async requests once I feel like doing it
  374. %group Reddit_v3
  375. %hook CommentView
  376. %new
  377. -(void) buttonAction {
  378. id commentsViewController = [self delegate];
  379. id comment = [self comment];
  380. NSError* error;
  381. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  382. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment pkWithoutPrefix]]]];
  383. [request setHTTPMethod:@"GET"];
  384. NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
  385. NSString *author = @"[author]";
  386. NSString *body = @"[body]";
  387. if (data != nil && error == nil){
  388. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  389. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  390. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  391. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  392. body = @"[comment was unable to be archived]";
  393. }
  394. } else if (error != nil || data == nil){
  395. body = @"[an error occured]";
  396. }
  397. [comment setValue:author forKey:@"author"];
  398. [comment setValue:[%c(MarkDownParser) attributedStringFromMarkdownString: body] forKey:@"bodyAttributedText"];
  399. [comment setValue:body forKey:@"bodyText"];
  400. [commentsViewController reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  401. }
  402. -(id) initWithFrame:(id)arg1{
  403. id orig = %orig;
  404. id commandView = [self commandView];
  405. UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  406. [undeleteButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
  407. UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  408. [undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
  409. [commandView setUndeleteButton:undeleteButton];
  410. [commandView addSubview:undeleteButton];
  411. return orig;
  412. }
  413. %end
  414. %hook CommentCommandView
  415. %property (assign, nonatomic) id undeleteButton;
  416. -(void) layoutSubviews{
  417. %orig;
  418. UIButton *button = [self undeleteButton];
  419. button.frame = CGRectMake([[self overflowButton ] frame].origin.x - 32, 0, 32, 32);
  420. }
  421. %end
  422. %end
  423. static void loadPrefs(){
  424. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
  425. if (prefs){
  426. isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
  427. isRedditEnabled = [prefs objectForKey:@"isRedditEnabled"] ? [[prefs objectForKey:@"isRedditEnabled"] boolValue] : YES;
  428. isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
  429. pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
  430. } else {
  431. isEnabled = YES;
  432. isRedditEnabled = YES;
  433. isTFDeletedOnly = YES;
  434. pushshiftRequestTimeoutValue = 10;
  435. }
  436. }
  437. static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  438. loadPrefs();
  439. }
  440. %ctor{
  441. loadPrefs();
  442. NSString* processName = [[NSProcessInfo processInfo] processName];
  443. @try {
  444. NSArray *redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
  445. firstVersionPart = [redditVersion[0] intValue];
  446. secondVersionPart = [redditVersion[1] intValue];
  447. }
  448. @catch (NSException *exc) {
  449. firstVersionPart = 2020;
  450. secondVersionPart = 0;
  451. }
  452. if ([processName isEqualToString:@"Reddit"]){
  453. if (isRedditEnabled && isEnabled) {
  454. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
  455. if (firstVersionPart == 4 || firstVersionPart == 2020) {
  456. if (secondVersionPart <= 32 && firstVersionPart != 2020) {
  457. %init(Reddit_v4_ios10);
  458. } else{
  459. %init(Reddit_v4_current);
  460. }
  461. } else if (firstVersionPart == 3) {
  462. %init(Reddit_v3);
  463. }
  464. }
  465. }
  466. }