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.

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