Sfoglia il codice sorgente

Improve preferences

master
lint 5 anni fa
parent
commit
3f3b9cf167
4 ha cambiato i file con 165 aggiunte e 45 eliminazioni
  1. +48
    -0
      prefs/Resources/Root.plist
  2. +41
    -14
      tweak/Apollo.xm
  3. +34
    -10
      tweak/Narwhal.xm
  4. +42
    -21
      tweak/Reddit.xm

+ 48
- 0
prefs/Resources/Root.plist Vedi File

@@ -4,6 +4,48 @@
<dict>
<key>items</key>
<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>
<key>cell</key>
<string>PSGroupCell</string>
@@ -48,6 +90,12 @@
<key>showValue</key>
<true/>
</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>
<key>title</key>
<string>TFDidThatSay?</string>

+ 41
- 14
tweak/Apollo.xm Vedi File

@@ -1,10 +1,9 @@
#import <Cephei/HBPreferences.h>
#import "Apollo.h"
HBPreferences *apolloPrefs;
BOOL isApolloDeletedCommentsOnly;
CGFloat apolloRequestTimeoutValue;
static BOOL isApolloDeletedCommentsOnly;
static BOOL isApolloEnabled;
static CGFloat pushshiftRequestTimeoutValue;
%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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[apolloPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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];
BOOL isDeletedOnly = [apolloPrefs boolForKey:@"isApolloDeletedCommentsOnly"];
if ((isDeletedOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isDeletedOnly) {
if ((isApolloDeletedCommentsOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isApolloDeletedCommentsOnly) {
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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[apolloPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@@ -238,15 +235,45 @@ NSDictionary* apolloBodyAttributes = nil;
%end
%ctor {
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
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;
}
apolloPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"];
[apolloPrefs registerBool:&isApolloDeletedCommentsOnly default:YES forKey:@"isApolloDeletedCommentsOnly"];
[apolloPrefs registerDouble:&apolloRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"];
} else {
isApolloEnabled = YES;
pushshiftRequestTimeoutValue = 10;
isApolloDeletedCommentsOnly = YES;
}
}
%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"Apollo"]){
%init(Apollo, ApolloCommentsHeaderCellNode = objc_getClass("Apollo.CommentsHeaderCellNode"), ApolloCommentCellNode = objc_getClass("Apollo.CommentCellNode"), ApolloApolloButtonNode = objc_getClass("Apollo.ApolloButtonNode"));
if (isApolloEnabled){
%init(Apollo, ApolloCommentsHeaderCellNode = objc_getClass("Apollo.CommentsHeaderCellNode"), ApolloCommentCellNode = objc_getClass("Apollo.CommentCellNode"), ApolloApolloButtonNode = objc_getClass("Apollo.ApolloButtonNode"));
}
}
}

+ 34
- 10
tweak/Narwhal.xm Vedi File

@@ -1,9 +1,8 @@
#import <Cephei/HBPreferences.h>
#import "Narwhal.h"
HBPreferences *narwhalPrefs;
CGFloat narwhalRequestTimeoutValue;
static BOOL isNarwhalEnabled;
static CGFloat pushshiftRequestTimeoutValue;

%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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[narwhalPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[narwhalPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@@ -212,15 +211,40 @@ void getUndeleteCommentData(id controller, id comment){
%end
%ctor {
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
narwhalPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"];
[narwhalPrefs registerDouble:&narwhalRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"];
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];

if ([processName isEqualToString:@"narwhal"]){
%init(Narwhal);
if ([processName isEqualToString:@"narwhal"]){
if (isNarwhalEnabled){
%init(Narwhal);
}
}
}

+ 42
- 21
tweak/Reddit.xm Vedi File

@@ -1,9 +1,8 @@
#import <Cephei/HBPreferences.h>
#import "Reddit.h"
HBPreferences *redditPrefs;
CGFloat redditRequestTimeoutValue;
static CGFloat pushshiftRequestTimeoutValue;
static BOOL isRedditEnabled;
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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@@ -712,25 +711,47 @@ NSArray *redditVersion;
%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{
redditPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"];
[redditPrefs registerDouble:&redditRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"];
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if ([processName isEqualToString:@"Reddit"]){
if ([redditVersion[0] isEqualToString:@"4"]){
if ([redditVersion[1] integerValue] <= 32){
%init(Reddit_v4_ios10);
} else{
%init(Reddit_v4_current);
}
} else if ([redditVersion[0] isEqualToString:@"3"]) {
%init(Reddit_v3);
if ([processName isEqualToString:@"Reddit"]){
if (isRedditEnabled) {
if ([redditVersion[0] isEqualToString:@"4"]){
if ([redditVersion[1] integerValue] <= 32){
%init(Reddit_v4_ios10);
} else{
%init(Reddit_v4_current);
}
} else if ([redditVersion[0] isEqualToString:@"3"]) {
%init(Reddit_v3);
}
}
}
}

Loading…
Annulla
Salva