Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pick up indexing where we left off, even if you're outside a sandbox.

  • Loading branch information...
commit 2b1c43c61f1265d0c4cdec0e2d6e7a00f72ad699 1 parent cd14754
@beelsebob authored
Showing with 48 additions and 15 deletions.
  1. +46 −13 Stash/STAAppDelegate.m
  2. +2 −2 Stash/Stash.entitlements
View
59 Stash/STAAppDelegate.m
@@ -231,6 +231,7 @@ - (IBAction)searchWithinPage:(id)sender
}
#define STADocumentationBookmarksKey @"DocsBookmarks"
+#define STADocumentationURLsKey @"DocsURLs"
- (IBAction)addDocumentation:(id)sender
{
@@ -255,6 +256,15 @@ - (IBAction)addDocumentation:(id)sender
[[NSUserDefaults standardUserDefaults] setObject:documentationBookmarks forKey:STADocumentationBookmarksKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
+ else
+ {
+ NSArray *documentationURLs = [[NSUserDefaults standardUserDefaults] arrayForKey:STADocumentationURLsKey];
+ documentationURLs = documentationURLs ? : @[];
+ NSString *urlString = [selectedRoot absoluteString];
+ documentationURLs = [documentationURLs containsObject:urlString] ? documentationURLs : [documentationURLs arrayByAddingObject:urlString];
+ [[NSUserDefaults standardUserDefaults] setObject:documentationURLs forKey:STADocumentationURLsKey];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ }
[self indexDocsetsWithPermissionInRoots:@[lastRoot] withContinuation:^(){}];
});
}];
@@ -334,21 +344,35 @@ - (void)readExistingIndexes
- (void)refreshExistingBookmarksWithContinuation:(void(^)(void))cont
{
- NSArray *documentationBookmarks = [[NSUserDefaults standardUserDefaults] arrayForKey:STADocumentationBookmarksKey];
- NSMutableArray *bookmarkURLs = [NSMutableArray arrayWithCapacity:[documentationBookmarks count]];
- for (NSData *bookmark in documentationBookmarks)
+ NSDictionary* environ = [[NSProcessInfo processInfo] environment];
+ BOOL inSandbox = (nil != [environ objectForKey:@"APP_SANDBOX_CONTAINER_ID"]);
+ NSMutableArray *urls = [NSMutableArray array];
+ if (inSandbox)
{
- BOOL stale = NO;
- NSError *err;
- NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark
- options:NSURLBookmarkResolutionWithSecurityScope
- relativeToURL:nil
- bookmarkDataIsStale:&stale
- error:&err];
- [url startAccessingSecurityScopedResource];
- [bookmarkURLs addObject:url];
+ NSArray *documentationBookmarks = [[NSUserDefaults standardUserDefaults] arrayForKey:STADocumentationBookmarksKey];
+ for (NSData *bookmark in documentationBookmarks)
+ {
+ BOOL stale = NO;
+ NSError *err = nil;
+ NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark
+ options:NSURLBookmarkResolutionWithSecurityScope
+ relativeToURL:nil
+ bookmarkDataIsStale:&stale
+ error:&err];
+ [url startAccessingSecurityScopedResource];
+ [urls addObject:url];
+ }
}
- [self indexDocsetsWithPermissionInRoots:bookmarkURLs withContinuation:cont];
+ else
+ {
+ NSArray *documentationURLs = [[NSUserDefaults standardUserDefaults] arrayForKey:STADocumentationURLsKey];
+ for (NSString *urlString in documentationURLs)
+ {
+ NSURL *url = [NSURL URLWithString:urlString];
+ [urls addObject:url];
+ }
+ }
+ [self indexDocsetsWithPermissionInRoots:urls withContinuation:cont];
}
- (void)indexDocsetsInRoots:(NSArray *)roots withContinuation:(void(^)(void))cont
@@ -382,6 +406,15 @@ - (void)indexDocsetsInRoots:(NSArray *)originalRoots index:(NSUInteger)idx selec
[[NSUserDefaults standardUserDefaults] setObject:documentationBookmarks forKey:STADocumentationBookmarksKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
+ else
+ {
+ NSArray *documentationURLs = [[NSUserDefaults standardUserDefaults] arrayForKey:STADocumentationURLsKey];
+ documentationURLs = documentationURLs ? : @[];
+ NSString *urlString = [selectedRoot absoluteString];
+ documentationURLs = [documentationURLs containsObject:urlString] ? documentationURLs : [documentationURLs arrayByAddingObject:urlString];
+ [[NSUserDefaults standardUserDefaults] setObject:documentationURLs forKey:STADocumentationURLsKey];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ }
[self indexDocsetsInRoots:originalRoots index:idx+1 selectedRoots:[selectedRoots arrayByAddingObject:selectedRoot] withContinuation:cont];
});
View
4 Stash/Stash.entitlements
@@ -2,10 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>com.apple.security.files.bookmarks.app-scope</key>
- <true/>
<key>com.apple.security.app-sandbox</key>
<true/>
+ <key>com.apple.security.files.bookmarks.app-scope</key>
+ <true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
Please sign in to comment.
Something went wrong with that request. Please try again.