No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

682 líneas
21KB

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