mirror of
https://github.com/lint/TFDidThatSay
synced 2025-07-04 16:36:46 +00:00
Fix Reddit crash when getting version part
This commit is contained in:
@ -6,22 +6,8 @@ static BOOL isRedditEnabled;
|
|||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
static CGFloat pushshiftRequestTimeoutValue;
|
static CGFloat pushshiftRequestTimeoutValue;
|
||||||
|
|
||||||
static NSArray *redditVersion;
|
int firstVersionPart = 4;
|
||||||
|
int secondVersionPart = 49;
|
||||||
int getRedditVersionPart(int index){
|
|
||||||
|
|
||||||
if (![redditVersion[index] isEqual:[NSNull null]]){
|
|
||||||
return [redditVersion[index] intValue];
|
|
||||||
} else {
|
|
||||||
NSArray *newVersionArray = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
|
|
||||||
|
|
||||||
if (![newVersionArray[index] isEqual:[NSNull null]]){
|
|
||||||
return [newVersionArray[index] intValue];
|
|
||||||
} else {
|
|
||||||
return [@[@4, @48, @1][index] intValue];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%group Reddit_v4_current
|
%group Reddit_v4_current
|
||||||
|
|
||||||
@ -114,7 +100,7 @@ int getRedditVersionPart(int index){
|
|||||||
id isNightMode;
|
id isNightMode;
|
||||||
id textColor;
|
id textColor;
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 45){
|
if (secondVersionPart >= 45){
|
||||||
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
|
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
|
||||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
||||||
|
|
||||||
@ -126,7 +112,7 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
[themeManager release];
|
[themeManager release];
|
||||||
|
|
||||||
} else if (getRedditVersionPart(1) >= 37){
|
} else if (secondVersionPart >= 37){
|
||||||
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
|
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
|
||||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
||||||
|
|
||||||
@ -241,7 +227,7 @@ int getRedditVersionPart(int index){
|
|||||||
id isNightMode;
|
id isNightMode;
|
||||||
id textColor;
|
id textColor;
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 45){
|
if (secondVersionPart >= 45){
|
||||||
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
|
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
|
||||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
||||||
|
|
||||||
@ -253,7 +239,7 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
[themeManager release];
|
[themeManager release];
|
||||||
|
|
||||||
} else if (getRedditVersionPart(1) >= 37){
|
} else if (secondVersionPart >= 37){
|
||||||
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
|
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
|
||||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
|
||||||
|
|
||||||
@ -290,9 +276,9 @@ int getRedditVersionPart(int index){
|
|||||||
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
|
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
|
||||||
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
|
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 44){
|
if (secondVersionPart >= 44){
|
||||||
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
|
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
|
||||||
} else if (getRedditVersionPart(1) >= 38) {
|
} else if (secondVersionPart >= 38) {
|
||||||
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
|
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
|
||||||
} else {
|
} else {
|
||||||
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
|
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
|
||||||
@ -319,7 +305,7 @@ int getRedditVersionPart(int index){
|
|||||||
%new
|
%new
|
||||||
-(void) updatePostText{
|
-(void) updatePostText{
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 2){
|
if (secondVersionPart >= 2){
|
||||||
[self reloadPostSection:YES];
|
[self reloadPostSection:YES];
|
||||||
} else {
|
} else {
|
||||||
[self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
|
[self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
|
||||||
@ -345,7 +331,7 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
id undeleteItem;
|
id undeleteItem;
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 18) {
|
if (secondVersionPart >= 18) {
|
||||||
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
|
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
|
||||||
} else {
|
} else {
|
||||||
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
|
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
|
||||||
@ -400,7 +386,7 @@ int getRedditVersionPart(int index){
|
|||||||
[comment setBodyText:body];
|
[comment setBodyText:body];
|
||||||
[comment setBodyAttributedText:bodyMutableAttributedText];
|
[comment setBodyAttributedText:bodyMutableAttributedText];
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 12) {
|
if (secondVersionPart >= 12) {
|
||||||
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
|
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,7 +416,7 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
id undeleteItem;
|
id undeleteItem;
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 18) {
|
if (secondVersionPart >= 18) {
|
||||||
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
|
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
|
||||||
} else {
|
} else {
|
||||||
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
|
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
|
||||||
@ -492,11 +478,11 @@ int getRedditVersionPart(int index){
|
|||||||
[post setSelfText:body];
|
[post setSelfText:body];
|
||||||
[post setSelfTextAttributed:bodyMutableAttributedText];
|
[post setSelfTextAttributed:bodyMutableAttributedText];
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 8) {
|
if (secondVersionPart >= 8) {
|
||||||
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
|
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getRedditVersionPart(1) >= 15) {
|
if (secondVersionPart >= 15) {
|
||||||
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
|
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,20 +618,30 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
|
|||||||
loadPrefs();
|
loadPrefs();
|
||||||
|
|
||||||
NSString* processName = [[NSProcessInfo processInfo] processName];
|
NSString* processName = [[NSProcessInfo processInfo] processName];
|
||||||
redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
|
|
||||||
|
@try{
|
||||||
|
NSArray *redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
|
||||||
|
|
||||||
|
firstVersionPart = [redditVersion[0] intValue];
|
||||||
|
secondVersionPart = [redditVersion[1] intValue];
|
||||||
|
}
|
||||||
|
@catch (NSException *exc){
|
||||||
|
firstVersionPart = 4;
|
||||||
|
secondVersionPart = 49;
|
||||||
|
}
|
||||||
|
|
||||||
if ([processName isEqualToString:@"Reddit"]){
|
if ([processName isEqualToString:@"Reddit"]){
|
||||||
if (isRedditEnabled) {
|
if (isRedditEnabled) {
|
||||||
|
|
||||||
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
|
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
|
||||||
|
|
||||||
if (getRedditVersionPart(0) == 4){
|
if (firstVersionPart == 4){
|
||||||
if (getRedditVersionPart(1) <= 32){
|
if (secondVersionPart <= 32){
|
||||||
%init(Reddit_v4_ios10);
|
%init(Reddit_v4_ios10);
|
||||||
} else{
|
} else{
|
||||||
%init(Reddit_v4_current);
|
%init(Reddit_v4_current);
|
||||||
}
|
}
|
||||||
} else if (getRedditVersionPart(0) == 3) {
|
} else if (firstVersionPart == 3) {
|
||||||
%init(Reddit_v3);
|
%init(Reddit_v3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user