From 012ca186e801df499173a71c4e25d671ccc1aa34 Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 13:22:27 +0300 Subject: [PATCH 01/10] Improve formatting --- src/ios/FileOpener2.m | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 7161705..4b045df 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -30,8 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @synthesize controller = docController; - (void) open: (CDVInvokedUrlCommand*)command { - - NSString *path = [command.arguments objectAtIndex:0]; + NSString *path = [command.arguments objectAtIndex:0]; NSString *contentType = [command.arguments objectAtIndex:1]; BOOL showPreview = YES; @@ -55,18 +54,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dispatch_async(dispatch_get_main_queue(), ^{ NSURL *fileURL = NULL; NSString *decodedPath = [path stringByRemovingPercentEncoding]; + if ([path isEqualToString:decodedPath]) { - NSLog(@"Path parameter not encoded. Building file URL encoding it..."); - fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];; + NSLog(@"Path parameter not encoded. Building file URL encoding it..."); + fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];; } else { - NSLog(@"Path parameter already encoded. Building file URL without encoding it..."); - fileURL = [NSURL URLWithString:path]; + NSLog(@"Path parameter already encoded. Building file URL without encoding it..."); + fileURL = [NSURL URLWithString:path]; } localFile = fileURL.path; NSLog(@"looking for file at %@", fileURL); NSFileManager *fm = [NSFileManager defaultManager]; + if(![fm fileExistsAtPath:localFile]) { NSDictionary *jsonObj = @{@"status" : @"9", @"message" : @"File does not exist"}; @@ -85,12 +86,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CGRect rect; if ([command.arguments count] >= 4) { NSArray *positionValues = [command.arguments objectAtIndex:3]; - - if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) { - rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]); - } else { - rect = CGRectMake(0, 0, 0, 0); - } + + if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) { + rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]); + } else { + rect = CGRectMake(0, 0, 0, 0); + } } else { rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height); } @@ -116,6 +117,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; } + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }); } From 54a2370fe0b28609334f1abb4063566ffd91b54e Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 13:25:22 +0300 Subject: [PATCH 02/10] Remove commented out logging --- src/ios/FileOpener2.m | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 4b045df..dd86c8f 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -107,7 +107,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. if(wasOpened) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""]; - //NSLog(@"Success"); } else { NSDictionary *jsonObj = [ [NSDictionary alloc] initWithObjectsAndKeys : From 7892aa90fdc0bf449c6ad549d1cffd4169109af3 Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 13:41:11 +0300 Subject: [PATCH 03/10] Improve formatting --- src/ios/FileOpener2.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index dd86c8f..2553a8f 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -84,6 +84,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //Opens the file preview CGRect rect; + if ([command.arguments count] >= 4) { NSArray *positionValues = [command.arguments objectAtIndex:3]; @@ -105,7 +106,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. wasOpened = [docController presentOpenInMenuFromRect:rect inView:cont.view animated:YES]; } - if(wasOpened) { + if (wasOpened) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""]; } else { NSDictionary *jsonObj = [ [NSDictionary alloc] @@ -133,6 +134,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]){ presentingViewController = presentingViewController.presentedViewController; } + return presentingViewController; } @end From 048cd0ad4fd333bd10b06a734d717dcb618d1a0f Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 13:41:46 +0300 Subject: [PATCH 04/10] Return plugin result after the menu is dismissed --- src/ios/FileOpener2.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 2553a8f..3219e07 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -29,8 +29,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @implementation FileOpener2 @synthesize controller = docController; +CDVPluginResult* pluginResult = nil; +NSString* callbackId = nil; + - (void) open: (CDVInvokedUrlCommand*)command { - NSString *path = [command.arguments objectAtIndex:0]; + callbackId = command.callbackId; + NSString *path = [command.arguments objectAtIndex:0]; NSString *contentType = [command.arguments objectAtIndex:1]; BOOL showPreview = YES; @@ -117,14 +121,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; } - - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }); } @end @implementation FileOpener2 (UIDocumentInteractionControllerDelegate) + - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller { + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; + } + - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { UIViewController *presentingViewController = self.viewController; if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow){ From d2fb6d5184c6b5697079df7363f0f92320d23526 Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 15:30:05 +0300 Subject: [PATCH 05/10] Fix indentation inside delegate --- src/ios/FileOpener2.m | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 3219e07..6a921b2 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -127,20 +127,21 @@ NSString* callbackId = nil; @end @implementation FileOpener2 (UIDocumentInteractionControllerDelegate) - - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller { - [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; +- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller { + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; +} + +- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { + UIViewController *presentingViewController = self.viewController; + if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow){ + presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController; } - - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { - UIViewController *presentingViewController = self.viewController; - if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow){ - presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController; - } - - while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]){ - presentingViewController = presentingViewController.presentedViewController; - } - - return presentingViewController; + while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]){ + presentingViewController = presentingViewController.presentedViewController; } + + return presentingViewController; +} + @end From 68392bdaf2fca819dbf143b087d5c314ecf844fd Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 15:58:26 +0300 Subject: [PATCH 06/10] Remove unused variable & improve formatting --- src/ios/FileOpener2.m | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 6a921b2..74e7928 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -46,7 +46,7 @@ NSString* callbackId = nil; self.cdvViewController = cont; NSString *uti = nil; - if([contentType length] == 0){ + if ([contentType length] == 0) { NSArray *dotParts = [path componentsSeparatedByString:@"."]; NSString *fileExt = [dotParts lastObject]; @@ -72,7 +72,7 @@ NSString* callbackId = nil; NSLog(@"looking for file at %@", fileURL); NSFileManager *fm = [NSFileManager defaultManager]; - if(![fm fileExistsAtPath:localFile]) { + if (![fm fileExistsAtPath:localFile]) { NSDictionary *jsonObj = @{@"status" : @"9", @"message" : @"File does not exist"}; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; @@ -84,8 +84,6 @@ NSString* callbackId = nil; docController.delegate = self; docController.UTI = uti; - CDVPluginResult* pluginResult = nil; - //Opens the file preview CGRect rect; @@ -133,11 +131,12 @@ NSString* callbackId = nil; - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { UIViewController *presentingViewController = self.viewController; - if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow){ + + if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow) { presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController; } - while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]){ + while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) { presentingViewController = presentingViewController.presentedViewController; } From 64c15579ed85bb036eaf9be338331ae703b1fae4 Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 16:18:33 +0300 Subject: [PATCH 07/10] Apply same fix for open with preview functionality --- src/ios/FileOpener2.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 74e7928..3bc1d66 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -118,6 +118,7 @@ NSString* callbackId = nil; nil ]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; } }); } @@ -126,7 +127,11 @@ NSString* callbackId = nil; @implementation FileOpener2 (UIDocumentInteractionControllerDelegate) - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller { - [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; +} + +- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller { + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; } - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { From 32db98784da4df55ac749cb6b90acfee1be1fc5b Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 16:28:32 +0300 Subject: [PATCH 08/10] Fix indentations --- src/ios/FileOpener2.m | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 3bc1d66..0c93a61 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -69,15 +69,15 @@ NSString* callbackId = nil; localFile = fileURL.path; - NSLog(@"looking for file at %@", fileURL); - NSFileManager *fm = [NSFileManager defaultManager]; + NSLog(@"looking for file at %@", fileURL); + NSFileManager *fm = [NSFileManager defaultManager]; - if (![fm fileExistsAtPath:localFile]) { + if (![fm fileExistsAtPath:localFile]) { NSDictionary *jsonObj = @{@"status" : @"9", @"message" : @"File does not exist"}; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - return; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + return; } docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; @@ -91,7 +91,7 @@ NSString* callbackId = nil; NSArray *positionValues = [command.arguments objectAtIndex:3]; if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) { - rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]); + rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]); } else { rect = CGRectMake(0, 0, 0, 0); } @@ -118,7 +118,7 @@ NSString* callbackId = nil; nil ]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; } }); } @@ -127,11 +127,11 @@ NSString* callbackId = nil; @implementation FileOpener2 (UIDocumentInteractionControllerDelegate) - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller { - [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; } - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller { - [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; } - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { @@ -141,7 +141,7 @@ NSString* callbackId = nil; presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController; } - while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) { + while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) { presentingViewController = presentingViewController.presentedViewController; } From b5f4b19d71b40fc28db82ccb54a0daf92aecb198 Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 16:30:38 +0300 Subject: [PATCH 09/10] Add missing indentations not visible in editor --- src/ios/FileOpener2.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 0c93a61..8538ac0 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -91,9 +91,9 @@ NSString* callbackId = nil; NSArray *positionValues = [command.arguments objectAtIndex:3]; if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) { - rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]); - } else { - rect = CGRectMake(0, 0, 0, 0); + rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]); + } else { + rect = CGRectMake(0, 0, 0, 0); } } else { rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height); From c670fb46d6fd64bcc7e54d1ea775d8468d6f444d Mon Sep 17 00:00:00 2001 From: Aleksi Lahikainen Date: Tue, 8 Sep 2020 16:32:41 +0300 Subject: [PATCH 10/10] Fix indendations not visible in editor --- src/ios/FileOpener2.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 8538ac0..b02cf0e 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -90,11 +90,11 @@ NSString* callbackId = nil; if ([command.arguments count] >= 4) { NSArray *positionValues = [command.arguments objectAtIndex:3]; - if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) { + if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) { rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]); } else { rect = CGRectMake(0, 0, 0, 0); - } + } } else { rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height); }