Browse Source

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

Thomas Buck 10 years ago
parent
commit
5b29069430

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

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

+ 3
- 35
RedditBar/AppDelegate.m View File

43
     [statusItem setToolTip:NSLocalizedString(@"RedditBar", @"Main Menuitem Tooltip")];
43
     [statusItem setToolTip:NSLocalizedString(@"RedditBar", @"Main Menuitem Tooltip")];
44
     [statusItem setHighlightMode:YES];
44
     [statusItem setHighlightMode:YES];
45
     currentState = [[StateModel alloc] init];
45
     currentState = [[StateModel alloc] init];
46
-    [self defaultPreferences];
47
-    [self loadPreferences];
46
+    [currentState registerDefaultPreferences];
47
+    [currentState loadPreferences];
48
     lastFullName = nil;
48
     lastFullName = nil;
49
     [self reloadListWithOptions];
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
 -(void)reloadListNotAuthenticatedCallback {
52
 -(void)reloadListNotAuthenticatedCallback {
85
     [firstMenuItem setTitle:NSLocalizedString(@"Login Error!", @"Statusitem when API is not authenticated")];
53
     [firstMenuItem setTitle:NSLocalizedString(@"Login Error!", @"Statusitem when API is not authenticated")];
86
     [self clearMenuItems];
54
     [self clearMenuItems];
238
     currentState.subreddits = [subreddits componentsSeparatedByString: @"\n"];
206
     currentState.subreddits = [subreddits componentsSeparatedByString: @"\n"];
239
     currentState.length = length;
207
     currentState.length = length;
240
     currentState.showSubreddit = showSubreddits;
208
     currentState.showSubreddit = showSubreddits;
241
-    [self savePreferences];
209
+    [currentState savePreferences];
242
     lastFullName = nil; // reload from start
210
     lastFullName = nil; // reload from start
243
     [self reloadListWithOptions];
211
     [self reloadListWithOptions];
244
 }
212
 }

+ 8
- 7
RedditBar/Reddit.m View File

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

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

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

+ 10
- 0
RedditBar/RedditBar.entitlements View File

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
 @property (atomic) NSInteger length;
37
 @property (atomic) NSInteger length;
38
 @property (atomic) Boolean showSubreddit;
38
 @property (atomic) Boolean showSubreddit;
39
 
39
 
40
+-(void)registerDefaultPreferences;
41
+-(void)savePreferences;
42
+-(void)loadPreferences;
43
+
40
 @end
44
 @end

+ 34
- 1
RedditBar/StateModel.m View File

30
 
30
 
31
 @implementation StateModel
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
 @end
68
 @end

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

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

Loading…
Cancel
Save