Skip to content

Commit 310f69f

Browse files
author
Jeremy Kister
committed
initial release
1 parent ec19abc commit 310f69f

16 files changed

+957
-0
lines changed

APTTimeout.mm

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
# Copyright (c) 2016 Jeremy Kister
3+
# http://jeremy.kister.net./
4+
# Released under the Artistic License 2.0
5+
*/
6+
7+
#import <Preferences/Preferences.h>
8+
#import <Preferences/PSSpecifier.h>
9+
10+
#define DEBUG 0
11+
#define BITCOIN @"bitcoin://17nWouHyEueDiRf2vXA17Dpa9kMCXsmNVg"
12+
#define COINBASE @"https://www.coinbase.com/checkouts/56e137721a33709b4d0efceb335f35d9"
13+
#define PAYPAL @"https://www.paypal.com/myaccount/transfer/send/[email protected]&amount=&currencyCode=USD&payment_type=Gift"
14+
15+
#define TIMEOUT_FILE @"/etc/apt/apt.conf.d/99APTTimeout"
16+
17+
#if DEBUG
18+
# define debug(fmt, ...) NSLog((@"%s @ %d " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
19+
#else
20+
# define debug(...)
21+
#endif
22+
23+
@interface APTTimeoutListController : PSListController
24+
-(id)readPreferenceValue:(PSSpecifier*)specifier;
25+
-(void)setPreferenceValue:(id)value specifier:(PSSpecifier*)specifier;
26+
@end
27+
28+
@interface AuthorListController : PSListController
29+
@end
30+
31+
@implementation AuthorListController
32+
@end
33+
34+
@interface iPopup:NSObject
35+
-(void) title:(NSString *)UITitle message:(NSString *)UIMessage;
36+
@end
37+
38+
@implementation iPopup
39+
-(void) title:(NSString *)UITitle message:(NSString *)UIMessage {
40+
UIAlertView *alert = [
41+
[UIAlertView alloc]
42+
initWithTitle:UITitle
43+
message:UIMessage
44+
delegate:self
45+
cancelButtonTitle:@"OK"
46+
otherButtonTitles:nil
47+
];
48+
[alert show];
49+
[alert release];
50+
}
51+
@end
52+
53+
@implementation APTTimeoutListController
54+
- (NSArray *)specifiers {
55+
if (! _specifiers) {
56+
_specifiers = [[self loadSpecifiersFromPlistName:@"APTTimeout" target:self] retain];
57+
}
58+
return _specifiers;
59+
}
60+
61+
- (id)readPreferenceValue:(PSSpecifier*)specifier {
62+
NSString *path = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", specifier.properties[@"defaults"]];
63+
debug(@"path is: %@", path);
64+
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:path];
65+
NSString *value = (settings[specifier.properties[@"key"]]) ?:
66+
specifier.properties[@"default"] ;
67+
debug(@"returning: %@", value);
68+
return value;
69+
}
70+
71+
- (void)setPreferenceValue:(id)value specifier:(PSSpecifier*)specifier {
72+
NSString *path = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", specifier.properties[@"defaults"]];
73+
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
74+
[defaults addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
75+
debug(@"%@", specifier.properties[@"key"]);
76+
[defaults setObject:value forKey:specifier.properties[@"key"]];
77+
[defaults writeToFile:path atomically:YES];
78+
CFStringRef notificationName = (CFStringRef)specifier.properties[@"PostNotification"];
79+
if (notificationName) {
80+
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), notificationName, NULL, NULL, YES);
81+
}
82+
83+
#if DEBUG
84+
# NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:path];
85+
# debug(@"Settings: %@", settings);
86+
#endif
87+
88+
}
89+
90+
-(void)repo {
91+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"cydia://url/https://cydia.saurik.com/api/share#?source=http://kister.net/cydia/"]];
92+
}
93+
94+
-(void)twitter {
95+
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://user?screen_name=jkister"]]) {
96+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=jkister"]];
97+
}else{
98+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/jkister"]];
99+
}
100+
}
101+
102+
-(void)reddit {
103+
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alienblue://r/apttimeout"]]) {
104+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"alienblue://r/apttimeout"]];
105+
}else{
106+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://reddit.com/r/apttimeout"]];
107+
}
108+
}
109+
110+
-(void)paypal {
111+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:PAYPAL]];
112+
}
113+
114+
-(void)bitcoin {
115+
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:BITCOIN]]) {
116+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:BITCOIN]];
117+
}else{
118+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:COINBASE]];
119+
}
120+
}
121+
122+
-(void)apply {
123+
124+
/* this should eventually be a darwin hook
125+
https://github.com/angelXwind/PreferenceOrganizer2 */
126+
127+
NSString *http = nil;
128+
NSString *ftp = nil;
129+
NSMutableArray *specifiers = [[NSMutableArray alloc] initWithArray:((PSListController *)self).specifiers];
130+
for (int i=0; i < [specifiers count]; i++ ){
131+
PSSpecifier *item = [specifiers objectAtIndex:i];
132+
133+
if ([item.identifier isEqualToString:@"HTTP Timeout"]){
134+
http = [self readPreferenceValue:item];
135+
} else if ([item.identifier isEqualToString:@"FTP Timeout"]){
136+
ftp = [self readPreferenceValue:item];
137+
}
138+
139+
if ( http != nil && ftp != nil ){
140+
break;
141+
}
142+
143+
}
144+
145+
iPopup *popup = [[iPopup alloc] init];
146+
147+
debug(@"HTTP: %@ - FTP: %@", http, ftp);
148+
if( http == nil || ftp == nil ){
149+
[popup title:@"Error" message:@"Failure getting timeout values."];
150+
return;
151+
}
152+
153+
NSFileHandle *fh = [NSFileHandle fileHandleForUpdatingAtPath:TIMEOUT_FILE];
154+
if (fh == nil){
155+
debug(@"Could not open timeout file");
156+
[popup title:@"Error" message:@"Couldnt open timeout file"];
157+
return;
158+
}
159+
160+
[fh truncateFileAtOffset: 0];
161+
NSString *hline = [NSString stringWithFormat:@"Acquire::http::Timeout \"%@\";\n", http];
162+
NSString *fline = [NSString stringWithFormat:@"Acquire::ftp::Timeout \"%@\";\n", ftp];
163+
164+
[fh writeData:[hline dataUsingEncoding:NSASCIIStringEncoding]];
165+
[fh writeData:[fline dataUsingEncoding:NSASCIIStringEncoding]];
166+
[fh closeFile];
167+
168+
debug(@"Success HTTP %@ -- FTP %@", http, ftp);
169+
[popup title:@"Success" message:@"Timeouts updated."];
170+
}
171+
172+
173+
@end

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include theos/makefiles/common.mk
2+
3+
TARGET = iphone:clang:8.1:4.0
4+
export ARCHS = armv7 arm64
5+
export SDKVERSION=8.1
6+
7+
8+
BUNDLE_NAME = APTTimeout
9+
APTTimeout_FILES = APTTimeout.mm
10+
APTTimeout_INSTALL_PATH = /Library/PreferenceBundles
11+
APTTimeout_FRAMEWORKS = UIKit
12+
APTTimeout_PRIVATE_FRAMEWORKS = Preferences
13+
14+
include $(THEOS_MAKE_PATH)/bundle.mk
15+
16+
17+
internal-stage::
18+
$(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences$(ECHO_END)
19+
$(ECHO_NOTHING)cp entry.plist $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences/APTTimeout.plist$(ECHO_END)

Resources/APTTimeout.plist

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>id</key>
6+
<string>net.kister.APTTimeout</string>
7+
8+
<key>items</key>
9+
<array>
10+
<dict>
11+
<key>cell</key> <string>PSGroupCell</string>
12+
<key>label</key> <string>APT Timeout Settings</string>
13+
<key>alignment</key> <integer>1</integer>
14+
<key>footerText</key><string>NB: Cydia (via APT) requests 5 files from each repo, which may cause a 5x delay from the above values.</string>
15+
<key>footerAlignment</key> <integer>1</integer>
16+
</dict>
17+
18+
<dict>
19+
<key>cell</key> <string>PSLinkListCell</string>
20+
<key>detail</key> <string>PSListItemsController</string>
21+
<key>default</key> <integer>5</integer>
22+
<key>defaults</key> <string>net.kister.APTTimeout</string>
23+
<key>label</key> <string>HTTP Timeout</string>
24+
<key>key</key> <string>http</string>
25+
<key>validTitles</key>
26+
<array>
27+
<string>1</string>
28+
<string>2</string>
29+
<string>3</string>
30+
<string>4</string>
31+
<string>5</string>
32+
<string>10</string>
33+
<string>15</string>
34+
<string>20</string>
35+
<string>25</string>
36+
<string>30</string>
37+
</array>
38+
<key>validValues</key>
39+
<array>
40+
<integer>1</integer>
41+
<integer>2</integer>
42+
<integer>3</integer>
43+
<integer>4</integer>
44+
<integer>5</integer>
45+
<integer>10</integer>
46+
<integer>15</integer>
47+
<integer>20</integer>
48+
<integer>25</integer>
49+
<integer>30</integer>
50+
</array>
51+
</dict>
52+
53+
<dict>
54+
<key>cell</key> <string>PSLinkListCell</string>
55+
<key>detail</key> <string>PSListItemsController</string>
56+
<key>default</key> <integer>5</integer>
57+
<key>defaults</key> <string>net.kister.APTTimeout</string>
58+
<key>label</key> <string>FTP Timeout</string>
59+
<key>key</key> <string>ftp</string>
60+
<key>validTitles</key>
61+
<array>
62+
<string>1</string>
63+
<string>2</string>
64+
<string>3</string>
65+
<string>4</string>
66+
<string>5</string>
67+
<string>10</string>
68+
<string>15</string>
69+
<string>20</string>
70+
<string>25</string>
71+
<string>30</string>
72+
</array>
73+
<key>validValues</key>
74+
<array>
75+
<integer>1</integer>
76+
<integer>2</integer>
77+
<integer>3</integer>
78+
<integer>4</integer>
79+
<integer>5</integer>
80+
<integer>10</integer>
81+
<integer>15</integer>
82+
<integer>20</integer>
83+
<integer>25</integer>
84+
<integer>30</integer>
85+
</array>
86+
</dict>
87+
88+
<dict>
89+
<key>cell</key> <string>PSGroupCell</string>
90+
</dict>
91+
92+
<dict>
93+
<key>cell</key> <string>PSButtonCell</string>
94+
<key>label</key> <string>[APPLY SETTINGS]</string>
95+
<key>action</key> <string>apply</string>
96+
<key>alignment</key> <string>center</string>
97+
</dict>
98+
99+
<dict>
100+
<key>cell</key> <string>PSGroupCell</string>
101+
</dict>
102+
<dict>
103+
<key>cell</key> <string>PSLinkCell</string>
104+
<key>label</key> <string>Author</string>
105+
<key>icon</key> <string>img/jkister.png</string>
106+
<key>detail</key> <string>AuthorListController</string>
107+
</dict>
108+
109+
<dict>
110+
<key>cell</key> <string>PSGroupCell</string>
111+
<key>footerAlignment</key> <integer>1</integer>
112+
<key>footerText</key>
113+
<string>APTTimeout © 2016 Jeremy Kister.
114+
Released under the Artistic License 2.0.</string>
115+
</dict>
116+
117+
</array>
118+
119+
<key>title</key>
120+
<string>APTTimeout</string>
121+
</dict>
122+
</plist>

0 commit comments

Comments
 (0)