Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for recent documents in High Sierra #2403

Merged
merged 2 commits into from Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions Quicksilver/Code-QuickStepCore/QSObject_FileHandling.m
Expand Up @@ -35,8 +35,23 @@

NSMutableArray *documentsArray = [NSMutableArray arrayWithCapacity:0];
NSURL *url;
if ([NSApplication isElCapitan]) {
NSString *sflPath = [NSString stringWithFormat:pSharedFileListPathTemplate, bundleIdentifier];
if ([NSApplication isHighSierra]) {
NSString *sflPath = [NSString stringWithFormat:pSharedFileListPathTemplate, bundleIdentifier, @"sfl2"];
NSString *sflStandardized = [sflPath stringByStandardizingPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:sflStandardized isDirectory:nil]) {
NSDictionary *sflData = [NSKeyedUnarchiver unarchiveObjectWithFile:sflStandardized];
for (NSDictionary *item in sflData[@"items"]) {
NSData *bookmarkData = item[@"Bookmark"];
url = [NSURL URLByResolvingBookmarkData:bookmarkData options:NSURLBookmarkResolutionWithoutUI|NSURLBookmarkResolutionWithoutMounting relativeToURL:nil bookmarkDataIsStale:NO error:nil];
if (url && [url isFileURL]) {
[documentsArray addObject:[url path]];
}
}
}
return documentsArray;
}
else if ([NSApplication isElCapitan]) {
NSString *sflPath = [NSString stringWithFormat:pSharedFileListPathTemplate, bundleIdentifier, @"sfl"];
NSString *sflStandardized = [sflPath stringByStandardizingPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:sflStandardized isDirectory:nil]) {
NSDictionary *sflData = [NSKeyedUnarchiver unarchiveObjectWithFile:sflStandardized];
Expand Down Expand Up @@ -321,7 +336,7 @@ - (BOOL)objectHasChildren:(QSObject *)object {
// Does the app have valid recent documents
if (bundleIdentifier) {
if ([NSApplication isElCapitan]) {
NSString *sflPath = [NSString stringWithFormat:pSharedFileListPathTemplate, bundleIdentifier];
NSString *sflPath = [NSString stringWithFormat:pSharedFileListPathTemplate, bundleIdentifier, @"sfl"];
if ([[NSFileManager defaultManager] fileExistsAtPath:[sflPath stringByStandardizingPath] isDirectory:nil]) {
return YES;
}
Expand Down
4 changes: 2 additions & 2 deletions Quicksilver/Code-QuickStepCore/QSPaths.h
Expand Up @@ -9,7 +9,7 @@
#define pCrashReporterFolder [@"~/Library/Logs/DiagnosticReports" stringByStandardizingPath]
#define pShelfLocation QSApplicationSupportSubPath(@"Shelves/", NO)
#define pICloudDocumentsPrefix [@"~/Library/Mobile Documents/" stringByStandardizingPath]
#define pSharedFileListPathTemplate @"~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/%@.sfl"
#define pSharedFileListPathTemplate @"~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/%@.%@"
#define appSupportSubpath @"Application Support/Quicksilver/PlugIns"

#define psMainPlugInsLocation QSApplicationSupportSubPath(@"PlugIns/", NO)
Expand Down Expand Up @@ -46,4 +46,4 @@ NSString *QSApplicationSupportSubPath(NSString *subpath, BOOL create);
*
* @return NSString giving the of the path to the Quicksilver Application Support directory
*/
NSString *QSGetApplicationSupportFolder();
NSString *QSGetApplicationSupportFolder();
Expand Up @@ -129,4 +129,11 @@ typedef NSInteger QSApplicationLaunchStatusFlags;
@returns YES, if 10.12+. NO otherwise
*/
+ (BOOL)isSierra;

/**
Checks, if system is at least macOS 10.13 (High Sierra)

@returns YES, if 10.13+. NO otherwise
*/
+ (BOOL)isHighSierra;
@end
Expand Up @@ -201,4 +201,8 @@ + (BOOL)isElCapitan {
+ (BOOL)isSierra {
return ([NSApplication macOSXMajorVersion] >= 10 && [NSApplication macOSXMinorVersion] >= 12);
}

+ (BOOL)isHighSierra {
return ([NSApplication macOSXMajorVersion] >= 10 && [NSApplication macOSXMinorVersion] >= 13);
}
@end
43 changes: 29 additions & 14 deletions Quicksilver/PlugIns-Main/QSCorePlugIn/Code/QSSharedFileListSource.m
Expand Up @@ -37,6 +37,9 @@ - (NSArray *)objectsForEntry:(NSDictionary *)theEntry
NSMutableArray *sflItemArray = [NSMutableArray arrayWithCapacity:0];
NSString *sflPath = [settings objectForKey:kItemPath];
NSString *path = [sflPath stringByStandardizingPath];
if ([NSApplication isHighSierra]) {
path = [path stringByReplacingOccurrencesOfString:@".sfl" withString:@".sfl2"];
}
BOOL isDir = NO;
if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] || isDir) {
return nil;
Expand All @@ -46,22 +49,34 @@ - (NSArray *)objectsForEntry:(NSDictionary *)theEntry
if (![[sflData allKeys] containsObject:kItems]) {
return nil;
}
for (SFLListItem *item in sflData[kItems]) {
// item's class is SFLListItem
if ([item URL]) {
[sflItemArray addObject:item];
if ([NSApplication isHighSierra]) {
return [sflData[kItems] arrayByEnumeratingArrayUsingBlock:^id(NSDictionary *item) {
NSData *bookmarkData = item[@"Bookmark"];
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmarkData options:NSURLBookmarkResolutionWithoutUI|NSURLBookmarkResolutionWithoutMounting relativeToURL:nil bookmarkDataIsStale:NO error:nil];
if ([url isFileURL]) {
return [QSObject fileObjectWithFileURL:url];
}
return [QSObject URLObjectWithURL:[url absoluteString] title:item[@"Name"]];
}];
} else {
for (SFLListItem *item in sflData[kItems]) {
// item's class is SFLListItem
if ([item URL]) {
[sflItemArray addObject:item];
}
}
[sflItemArray sortUsingComparator:^NSComparisonResult(SFLListItem *item1, SFLListItem *item2) {
return item1.order > item2.order;
}];
return [sflItemArray arrayByEnumeratingArrayUsingBlock:^id(SFLListItem *item) {
NSURL *url = [item URL];
if ([url isFileURL]) {
return [QSObject fileObjectWithFileURL:url];
}
return [QSObject URLObjectWithURL:[[item URL] absoluteString] title:[item name]];
}];
}
[sflItemArray sortUsingComparator:^NSComparisonResult(SFLListItem *item1, SFLListItem *item2) {
return item1.order > item2.order;
}];
return [sflItemArray arrayByEnumeratingArrayUsingBlock:^id(SFLListItem *item) {
NSURL *url = [item URL];
if ([url isFileURL]) {
return [QSObject fileObjectWithFileURL:url];
}
return [QSObject URLObjectWithURL:[[item URL] absoluteString] title:[item name]];
}];
return nil;
}

@end