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

Receive docset with AirDrop or any other file sharing medium #36

Merged
merged 3 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions Dash/DHAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,25 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)actualURL sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
[[NSNotificationCenter defaultCenter] postNotificationName:DHPrepareForURLSearch object:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:DHPerformURLSearch object:[actualURL absoluteString]];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

NSError *regexError;
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"Inbox/.+[\\.docset]$" options:0 error:&regexError];
if (regexError) {
return;
}
NSArray *matches = [regex matchesInString:[actualURL absoluteString] options:0 range:NSMakeRange(0, [actualURL absoluteString].length)];
if (matches.count) {

[self moveInboxContentsToDocuments];

}

[[NSNotificationCenter defaultCenter] postNotificationName:DHPrepareForURLSearch object:nil];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you post this asynchronously now? Why post it at all in the case when you're handling a docset?

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:DHPerformURLSearch object:[actualURL absoluteString]];
});
});
return YES;
}
Expand Down Expand Up @@ -247,4 +263,22 @@ - (DHWindow *)window
return self._window;
}

- (void)moveInboxContentsToDocuments {

NSError *fileManagerError;

NSString *inboxDirectory = [NSString stringWithFormat:@"%@/Inbox", transfersPath];
NSArray *inboxContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:inboxDirectory error:&fileManagerError];

//move all the files over
for (int i = 0; i != [inboxContents count]; i++) {
NSString *oldPath = [NSString stringWithFormat:@"%@/%@", inboxDirectory, [inboxContents objectAtIndex:i]];
NSString *newPath = [NSString stringWithFormat:@"%@/%@", transfersPath, [inboxContents objectAtIndex:i]];
[[NSFileManager defaultManager] moveItemAtPath:oldPath toPath:newPath error:&fileManagerError];
if (fileManagerError) {
NSLog(@"%@",fileManagerError.localizedDescription);
}
}
}

@end
4 changes: 4 additions & 0 deletions Dash/Dash iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
26480C2B1E2E9ABB00E3145E /* docset_icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 26480C2A1E2E9ABB00E3145E /* docset_icon.png */; };
4303A3BC19C6584F00A7CD85 /* whitespace_tokenizer.c in Sources */ = {isa = PBXBuildFile; fileRef = 4303A3B119C6584F00A7CD85 /* whitespace_tokenizer.c */; };
4303A3BD19C6584F00A7CD85 /* FMDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 4303A3B319C6584F00A7CD85 /* FMDatabase.m */; };
4303A3BE19C6584F00A7CD85 /* FMDatabaseAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4303A3B519C6584F00A7CD85 /* FMDatabaseAdditions.m */; };
Expand Down Expand Up @@ -127,6 +128,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
26480C2A1E2E9ABB00E3145E /* docset_icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = docset_icon.png; sourceTree = "<group>"; };
4303A3B019C6584F00A7CD85 /* whitespace_tokenizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = whitespace_tokenizer.h; sourceTree = "<group>"; };
4303A3B119C6584F00A7CD85 /* whitespace_tokenizer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = whitespace_tokenizer.c; sourceTree = "<group>"; };
4303A3B219C6584F00A7CD85 /* FMDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabase.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -743,6 +745,7 @@
433BDDB11DC3C3AC00B0B145 /* Settings.bundle */,
43BB045019ED48BD000FBC0D /* ClassRuby.png */,
43BB045119ED48BD000FBC0D /* ClassRubyRetina.png */,
26480C2A1E2E9ABB00E3145E /* docset_icon.png */,
43BB045219ED48BD000FBC0D /* ModuleRuby.png */,
43BB045319ED48BD000FBC0D /* ModuleRubyRetina.png */,
);
Expand Down Expand Up @@ -930,6 +933,7 @@
43BD91EE1AB31A9E001058C4 /* hash_change_notifier.js in Resources */,
43FD2EF019BB8D87007E594D /* InfoPlist.strings in Resources */,
43BB045719ED48BD000FBC0D /* ModuleRubyRetina.png in Resources */,
26480C2B1E2E9ABB00E3145E /* docset_icon.png in Resources */,
433BDDAE1DC3BE7700B0B145 /* ionicons.ttf in Resources */,
43BB045519ED48BD000FBC0D /* ClassRubyRetina.png in Resources */,
438E864A1D1D4A3C00FB6CD8 /* apple.js in Resources */,
Expand Down
33 changes: 33 additions & 0 deletions Dash/Dash-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>docset_icon.png</string>
<key>CFBundleTypeName</key>
<string>Docset File Type Handler</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.kapeli.dash.ios.docset</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
Expand Down Expand Up @@ -119,5 +134,23 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Docset File Type Handler</string>
<key>UTTypeIdentifier</key>
<string>com.kapeli.dash.ios.docset</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>docset</string>
</dict>
</dict>
</array>
</dict>
</plist>
Binary file added Dash/docset_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.