選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

690 行
22KB

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