您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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