1
0
mirror of https://github.com/lint/TFDidThatSay synced 2025-07-01 23:46:47 +00:00

Improve preferences

This commit is contained in:
lint
2019-11-21 19:06:28 -05:00
parent bb602d1121
commit 3f3b9cf167
4 changed files with 165 additions and 45 deletions

View File

@ -4,6 +4,48 @@
<dict> <dict>
<key>items</key> <key>items</key>
<array> <array>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Enabled</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>com.lint.undelete.prefs</string>
<key>key</key>
<string>isRedditEnabled</string>
<key>label</key>
<string>Enable Reddit</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>com.lint.undelete.prefs</string>
<key>key</key>
<string>isApolloEnabled</string>
<key>label</key>
<string>Enable Apollo</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>com.lint.undelete.prefs</string>
<key>key</key>
<string>isNarwhalEnabled</string>
<key>label</key>
<string>Enable Narwhal</string>
</dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>
@ -48,6 +90,12 @@
<key>showValue</key> <key>showValue</key>
<true/> <true/>
</dict> </dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>In order to apply preferences, restart the app. If changes do not immediately take effect, wait a few seconds and try again.</string>
</dict>
</array> </array>
<key>title</key> <key>title</key>
<string>TFDidThatSay?</string> <string>TFDidThatSay?</string>

View File

@ -1,10 +1,9 @@
#import <Cephei/HBPreferences.h>
#import "Apollo.h" #import "Apollo.h"
HBPreferences *apolloPrefs; static BOOL isApolloDeletedCommentsOnly;
BOOL isApolloDeletedCommentsOnly; static BOOL isApolloEnabled;
CGFloat apolloRequestTimeoutValue; static CGFloat pushshiftRequestTimeoutValue;
%group Apollo %group Apollo
@ -54,7 +53,7 @@ NSDictionary* apolloBodyAttributes = nil;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[apolloPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -97,9 +96,7 @@ NSDictionary* apolloBodyAttributes = nil;
id commentBody = [MSHookIvar<id>(self, "comment") body]; id commentBody = [MSHookIvar<id>(self, "comment") body];
BOOL isDeletedOnly = [apolloPrefs boolForKey:@"isApolloDeletedCommentsOnly"]; if ((isApolloDeletedCommentsOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isApolloDeletedCommentsOnly) {
if ((isDeletedOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isDeletedOnly) {
CGFloat imageSize = 20.0f; CGFloat imageSize = 20.0f;
@ -157,7 +154,7 @@ NSDictionary* apolloBodyAttributes = nil;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[apolloPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -238,15 +235,45 @@ NSDictionary* apolloBodyAttributes = nil;
%end %end
%ctor { static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
apolloPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"]; if (prefs){
[apolloPrefs registerBool:&isApolloDeletedCommentsOnly default:YES forKey:@"isApolloDeletedCommentsOnly"];
[apolloPrefs registerDouble:&apolloRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"]; if ([prefs objectForKey:@"isApolloEnabled"] != nil) {
isApolloEnabled = [[prefs objectForKey:@"isApolloEnabled"] boolValue];
} else {
isApolloEnabled = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
if ([prefs objectForKey:@"isApolloDeletedCommentsOnly"] != nil) {
isApolloDeletedCommentsOnly = [[prefs objectForKey:@"isApolloDeletedCommentsOnly"] boolValue];
} else {
isApolloDeletedCommentsOnly = YES;
}
} else {
isApolloEnabled = YES;
pushshiftRequestTimeoutValue = 10;
isApolloDeletedCommentsOnly = YES;
}
}
%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName]; NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"Apollo"]){ if ([processName isEqualToString:@"Apollo"]){
if (isApolloEnabled){
%init(Apollo, ApolloCommentsHeaderCellNode = objc_getClass("Apollo.CommentsHeaderCellNode"), ApolloCommentCellNode = objc_getClass("Apollo.CommentCellNode"), ApolloApolloButtonNode = objc_getClass("Apollo.ApolloButtonNode")); %init(Apollo, ApolloCommentsHeaderCellNode = objc_getClass("Apollo.CommentsHeaderCellNode"), ApolloCommentCellNode = objc_getClass("Apollo.CommentCellNode"), ApolloApolloButtonNode = objc_getClass("Apollo.ApolloButtonNode"));
} }
}
} }

View File

@ -1,9 +1,8 @@
#import <Cephei/HBPreferences.h>
#import "Narwhal.h" #import "Narwhal.h"
HBPreferences *narwhalPrefs; static BOOL isNarwhalEnabled;
CGFloat narwhalRequestTimeoutValue; static CGFloat pushshiftRequestTimeoutValue;
%group Narwhal %group Narwhal
@ -18,7 +17,7 @@ void getUndeleteCommentData(id controller, id comment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[narwhalPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -112,7 +111,7 @@ void getUndeleteCommentData(id controller, id comment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[narwhalPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -212,15 +211,40 @@ void getUndeleteCommentData(id controller, id comment){
%end %end
%ctor {
narwhalPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"]; static void loadPrefs(){
[narwhalPrefs registerDouble:&narwhalRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"]; NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isNarwhalEnabled"] != nil){
isNarwhalEnabled = [[prefs objectForKey:@"isNarwhalEnabled"] boolValue];
} else {
isNarwhalEnabled = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
} else {
isNarwhalEnabled = YES;
pushshiftRequestTimeoutValue = 10;
}
}
%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName]; NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"narwhal"]){ if ([processName isEqualToString:@"narwhal"]){
if (isNarwhalEnabled){
%init(Narwhal); %init(Narwhal);
} }
}
} }

View File

@ -1,9 +1,8 @@
#import <Cephei/HBPreferences.h>
#import "Reddit.h" #import "Reddit.h"
HBPreferences *redditPrefs; static CGFloat pushshiftRequestTimeoutValue;
CGFloat redditRequestTimeoutValue; static BOOL isRedditEnabled;
NSArray *redditVersion; NSArray *redditVersion;
@ -78,7 +77,7 @@ NSArray *redditVersion;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -223,7 +222,7 @@ NSArray *redditVersion;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -379,7 +378,7 @@ NSArray *redditVersion;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -432,7 +431,7 @@ NSArray *redditVersion;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -523,7 +522,7 @@ NSArray *redditVersion;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -579,7 +578,7 @@ NSArray *redditVersion;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]]; [request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -712,17 +711,38 @@ NSArray *redditVersion;
%end %end
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isRedditEnabled"] != nil){
isRedditEnabled = [[prefs objectForKey:@"isRedditEnabled"] boolValue];
} else {
isRedditEnabled = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
} else {
isRedditEnabled = YES;
pushshiftRequestTimeoutValue = 10;
}
}
%ctor{ %ctor{
loadPrefs();
redditPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"];
[redditPrefs registerDouble:&redditRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"];
NSString* processName = [[NSProcessInfo processInfo] processName]; NSString* processName = [[NSProcessInfo processInfo] processName];
redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."]; redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if ([processName isEqualToString:@"Reddit"]){ if ([processName isEqualToString:@"Reddit"]){
if (isRedditEnabled) {
if ([redditVersion[0] isEqualToString:@"4"]){ if ([redditVersion[0] isEqualToString:@"4"]){
if ([redditVersion[1] integerValue] <= 32){ if ([redditVersion[1] integerValue] <= 32){
%init(Reddit_v4_ios10); %init(Reddit_v4_ios10);
@ -733,4 +753,5 @@ NSArray *redditVersion;
%init(Reddit_v3); %init(Reddit_v3);
} }
} }
}
} }