Browse Source

Put persistent pref storage into StateModel. Turned on App Sandbox.

Thomas Buck 11 years ago
parent
commit
5b29069430

+ 13
- 0
RedditBar.xcodeproj/project.pbxproj View File

@@ -74,6 +74,7 @@
74 74
 		E9CF1F4A184961020004AE02 /* RedditBarTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RedditBarTests.m; sourceTree = "<group>"; };
75 75
 		E9CF1F5A1849685C0004AE02 /* PrefController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrefController.h; sourceTree = "<group>"; };
76 76
 		E9CF1F5B1849685C0004AE02 /* PrefController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrefController.m; sourceTree = "<group>"; };
77
+		E9F64A2B185D51C100D6CA16 /* RedditBar.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = RedditBar.entitlements; sourceTree = "<group>"; };
77 78
 /* End PBXFileReference section */
78 79
 
79 80
 /* Begin PBXFrameworksBuildPhase section */
@@ -139,6 +140,7 @@
139 140
 		E9CF1F26184961010004AE02 /* RedditBar */ = {
140 141
 			isa = PBXGroup;
141 142
 			children = (
143
+				E9F64A2B185D51C100D6CA16 /* RedditBar.entitlements */,
142 144
 				E9CF1F32184961010004AE02 /* AppDelegate.h */,
143 145
 				E9CF1F33184961010004AE02 /* AppDelegate.m */,
144 146
 				E9B6773C184B73DC00850559 /* Reddit.h */,
@@ -237,6 +239,13 @@
237 239
 				LastUpgradeCheck = 0500;
238 240
 				ORGANIZATIONNAME = xythobuz;
239 241
 				TargetAttributes = {
242
+					E9CF1F1C184961010004AE02 = {
243
+						SystemCapabilities = {
244
+							com.apple.Sandbox = {
245
+								enabled = 1;
246
+							};
247
+						};
248
+					};
240 249
 					E9CF1F3D184961020004AE02 = {
241 250
 						TestTargetID = E9CF1F1C184961010004AE02;
242 251
 					};
@@ -479,6 +488,8 @@
479 488
 			isa = XCBuildConfiguration;
480 489
 			buildSettings = {
481 490
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
491
+				CODE_SIGN_ENTITLEMENTS = RedditBar/RedditBar.entitlements;
492
+				CODE_SIGN_IDENTITY = "-";
482 493
 				COMBINE_HIDPI_IMAGES = YES;
483 494
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
484 495
 				GCC_PREFIX_HEADER = "RedditBar/RedditBar-Prefix.pch";
@@ -493,6 +504,8 @@
493 504
 			isa = XCBuildConfiguration;
494 505
 			buildSettings = {
495 506
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
507
+				CODE_SIGN_ENTITLEMENTS = RedditBar/RedditBar.entitlements;
508
+				CODE_SIGN_IDENTITY = "-";
496 509
 				COMBINE_HIDPI_IMAGES = YES;
497 510
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
498 511
 				GCC_PREFIX_HEADER = "RedditBar/RedditBar-Prefix.pch";

+ 3
- 35
RedditBar/AppDelegate.m View File

@@ -43,44 +43,12 @@
43 43
     [statusItem setToolTip:NSLocalizedString(@"RedditBar", @"Main Menuitem Tooltip")];
44 44
     [statusItem setHighlightMode:YES];
45 45
     currentState = [[StateModel alloc] init];
46
-    [self defaultPreferences];
47
-    [self loadPreferences];
46
+    [currentState registerDefaultPreferences];
47
+    [currentState loadPreferences];
48 48
     lastFullName = nil;
49 49
     [self reloadListWithOptions];
50 50
 }
51 51
 
52
--(void)defaultPreferences {
53
-    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
54
-    NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObject:@"" forKey:@"username"];
55
-    [appDefaults setValue:@"" forKey:@"modhash"];
56
-    [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:@"subscriptions"];
57
-    [appDefaults setValue:[NSNumber numberWithInt:10] forKey:@"length"];
58
-    [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:@"showSubs"];
59
-    [store registerDefaults:appDefaults];
60
-}
61
-
62
--(void)savePreferences {
63
-    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
64
-    [store setObject:currentState.username forKey:@"username"];
65
-    [store setObject:currentState.modhash forKey:@"modhash"];
66
-    [store setBool:currentState.useSubscriptions forKey:@"subscriptions"];
67
-    [store setObject:currentState.subreddits forKey:@"subreddits"];
68
-    [store setInteger:currentState.length forKey:@"length"];
69
-    [store setBool:currentState.showSubreddit forKey:@"showSubs"];
70
-    [store synchronize];
71
-}
72
-
73
--(void)loadPreferences {
74
-    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
75
-    [store synchronize];
76
-    [currentState setUsername:[store stringForKey:@"username"]];
77
-    [currentState setModhash:[store stringForKey:@"modhash"]];
78
-    [currentState setUseSubscriptions:[store boolForKey:@"subscriptions"]];
79
-    [currentState setSubreddits:[store arrayForKey:@"subreddits"]];
80
-    [currentState setLength:[store integerForKey:@"length"]];
81
-    [currentState setShowSubreddit:[store boolForKey:@"showSubs"]];
82
-}
83
-
84 52
 -(void)reloadListNotAuthenticatedCallback {
85 53
     [firstMenuItem setTitle:NSLocalizedString(@"Login Error!", @"Statusitem when API is not authenticated")];
86 54
     [self clearMenuItems];
@@ -238,7 +206,7 @@
238 206
     currentState.subreddits = [subreddits componentsSeparatedByString: @"\n"];
239 207
     currentState.length = length;
240 208
     currentState.showSubreddit = showSubreddits;
241
-    [self savePreferences];
209
+    [currentState savePreferences];
242 210
     lastFullName = nil; // reload from start
243 211
     [self reloadListWithOptions];
244 212
 }

+ 8
- 7
RedditBar/Reddit.m View File

@@ -194,17 +194,19 @@ NSString *subredditFormat = @" [r/%@]";
194 194
 
195 195
 -(void)isAuthenticatedNewModhash:(id)parent {
196 196
     NSHTTPURLResponse *response;
197
-    NSData *data = [self queryAPI:@"api/me.json" withResponse:&response];
198
-    if ((data != nil) && ([response statusCode] == 200)) {
197
+    NSData *dat = [self queryAPI:@"api/me.json" withResponse:&response];
198
+    if ((dat != nil) && ([response statusCode] == 200)) {
199 199
         NSError *error;
200
-        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
200
+        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dat options:0 error:&error];
201 201
         NSDictionary *data = [json valueForKey:@"data"];
202 202
         if (data == nil) {
203
+            NSLog(@"Not logged in!");
203 204
             [parent performSelectorOnMainThread:@selector(reloadListNotAuthenticatedCallback) withObject:nil waitUntilDone:false];
204 205
             return;
205 206
         }
206 207
         NSString *newHash = [data valueForKey:@"modhash"];
207 208
         if ((newHash == nil) || ([newHash isEqualToString:@""])) {
209
+            NSLog(@"Did not receive modhash!");
208 210
             [parent performSelectorOnMainThread:@selector(reloadListNotAuthenticatedCallback) withObject:nil waitUntilDone:false];
209 211
             return;
210 212
         }
@@ -231,8 +233,7 @@ NSString *subredditFormat = @" [r/%@]";
231 233
     NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:res error:&error];
232 234
     if (error)
233 235
         return nil;
234
-    else
235
-        return data;
236
+    return data;
236 237
 }
237 238
 
238 239
 -(NSData *)queryAPI:(NSString *)api withData:(NSString *)string andResponse:(NSHTTPURLResponse **)res {
@@ -246,14 +247,14 @@ NSString *subredditFormat = @" [r/%@]";
246 247
     [request setValue:[NSString stringWithFormat:@"%@/%@ by %@", appName, version, author] forHTTPHeaderField:@"User-Agent"];
247 248
     if ((modhash != nil) && (![modhash isEqualToString:@""]))
248 249
         [request addValue:modhash forHTTPHeaderField:@"X-Modhash"];
250
+    
249 251
     [request setHTTPMethod:@"POST"];
250 252
     [request setHTTPBody:requestBodyData];
251 253
     NSError *error = nil;
252 254
     NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:res error:&error];
253 255
     if (error)
254 256
         return nil;
255
-    else
256
-        return data;
257
+    return data;
257 258
 }
258 259
 
259 260
 -(NSURL *)getAPIPoint:(NSString *)where {

+ 1
- 1
RedditBar/RedditBar-Info.plist View File

@@ -21,7 +21,7 @@
21 21
 	<key>CFBundleSignature</key>
22 22
 	<string>????</string>
23 23
 	<key>CFBundleVersion</key>
24
-	<string>187</string>
24
+	<string>204</string>
25 25
 	<key>LSApplicationCategoryType</key>
26 26
 	<string>public.app-category.utilities</string>
27 27
 	<key>LSMinimumSystemVersion</key>

+ 10
- 0
RedditBar/RedditBar.entitlements View File

@@ -0,0 +1,10 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+<plist version="1.0">
4
+<dict>
5
+	<key>com.apple.security.app-sandbox</key>
6
+	<true/>
7
+	<key>com.apple.security.network.client</key>
8
+	<true/>
9
+</dict>
10
+</plist>

+ 4
- 0
RedditBar/StateModel.h View File

@@ -37,4 +37,8 @@
37 37
 @property (atomic) NSInteger length;
38 38
 @property (atomic) Boolean showSubreddit;
39 39
 
40
+-(void)registerDefaultPreferences;
41
+-(void)savePreferences;
42
+-(void)loadPreferences;
43
+
40 44
 @end

+ 34
- 1
RedditBar/StateModel.m View File

@@ -30,6 +30,39 @@
30 30
 
31 31
 @implementation StateModel
32 32
 
33
-@synthesize username, modhash, useSubscriptions, subreddits, showSubreddit;
33
+@synthesize username, modhash, useSubscriptions, subreddits, length, showSubreddit;
34
+
35
+-(void)registerDefaultPreferences {
36
+    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
37
+    NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObject:@"" forKey:@"username"];
38
+    [appDefaults setValue:@"" forKey:@"modhash"];
39
+    [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:@"subscriptions"];
40
+    [appDefaults setValue:[NSNumber numberWithInt:10] forKey:@"length"];
41
+    [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:@"showSubs"];
42
+    [appDefaults setValue:@"" forKey:@"session"];
43
+    [store registerDefaults:appDefaults];
44
+}
45
+
46
+-(void)savePreferences {
47
+    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
48
+    [store setObject:username forKey:@"username"];
49
+    [store setObject:modhash forKey:@"modhash"];
50
+    [store setBool:useSubscriptions forKey:@"subscriptions"];
51
+    [store setObject:subreddits forKey:@"subreddits"];
52
+    [store setInteger:length forKey:@"length"];
53
+    [store setBool:showSubreddit forKey:@"showSubs"];
54
+    [store synchronize];
55
+}
56
+
57
+-(void)loadPreferences {
58
+    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
59
+    [store synchronize];
60
+    username = [store stringForKey:@"username"];
61
+    modhash = [store stringForKey:@"modhash"];
62
+    useSubscriptions = [store boolForKey:@"subscriptions"];
63
+    subreddits = [store arrayForKey:@"subreddits"];
64
+    length = [store integerForKey:@"length"];
65
+    showSubreddit = [store boolForKey:@"showSubs"];
66
+}
34 67
 
35 68
 @end

+ 1
- 1
RedditBar/de.lproj/Localizable.strings View File

@@ -17,7 +17,7 @@
17 17
 "Loading..." = "Lade...";
18 18
 
19 19
 /* Statusitem when API is not authenticated */
20
-"Login Error!" = "Fehler beim login!";
20
+"Login Error!" = "Fehler beim Login!";
21 21
 
22 22
 /* Statusitem when no modhash is stored */
23 23
 "Not logged in!" = "Nicht eingeloggt!";

Loading…
Cancel
Save