Improve formatting

This commit is contained in:
Aleksi Lahikainen 2020-09-08 13:22:27 +03:00
parent eabe4a1e16
commit 012ca186e8

View File

@ -30,8 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@synthesize controller = docController; @synthesize controller = docController;
- (void) open: (CDVInvokedUrlCommand*)command { - (void) open: (CDVInvokedUrlCommand*)command {
NSString *path = [command.arguments objectAtIndex:0];
NSString *path = [command.arguments objectAtIndex:0];
NSString *contentType = [command.arguments objectAtIndex:1]; NSString *contentType = [command.arguments objectAtIndex:1];
BOOL showPreview = YES; 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(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSURL *fileURL = NULL; NSURL *fileURL = NULL;
NSString *decodedPath = [path stringByRemovingPercentEncoding]; NSString *decodedPath = [path stringByRemovingPercentEncoding];
if ([path isEqualToString:decodedPath]) { if ([path isEqualToString:decodedPath]) {
NSLog(@"Path parameter not encoded. Building file URL encoding it..."); NSLog(@"Path parameter not encoded. Building file URL encoding it...");
fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];; fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];;
} else { } else {
NSLog(@"Path parameter already encoded. Building file URL without encoding it..."); NSLog(@"Path parameter already encoded. Building file URL without encoding it...");
fileURL = [NSURL URLWithString:path]; fileURL = [NSURL URLWithString:path];
} }
localFile = fileURL.path; localFile = fileURL.path;
NSLog(@"looking for file at %@", fileURL); NSLog(@"looking for file at %@", fileURL);
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
if(![fm fileExistsAtPath:localFile]) { if(![fm fileExistsAtPath:localFile]) {
NSDictionary *jsonObj = @{@"status" : @"9", NSDictionary *jsonObj = @{@"status" : @"9",
@"message" : @"File does not exist"}; @"message" : @"File does not exist"};
@ -86,11 +87,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if ([command.arguments count] >= 4) { if ([command.arguments count] >= 4) {
NSArray *positionValues = [command.arguments objectAtIndex:3]; 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]); rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]);
} else { } else {
rect = CGRectMake(0, 0, 0, 0); rect = CGRectMake(0, 0, 0, 0);
} }
} else { } else {
rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height); 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]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
} }
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}); });
} }