From 121ad5856e1d35bd4bea19b8d6946092bf3dc43f Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Wed, 7 Sep 2016 12:46:46 +0530 Subject: [PATCH] Fix background segue and disable email ui during uploading process --- AppBox.xcodeproj/project.pbxproj | 16 +++ AppBox/Base.lproj/Main.storyboard | 29 +++-- AppBox/Info.plist | 2 +- .../HomeViewController/HomeViewController.h | 23 ++-- .../HomeViewController/HomeViewController.m | 103 +++++++++++++----- .../ShowLinkViewController.m | 6 +- 6 files changed, 122 insertions(+), 57 deletions(-) diff --git a/AppBox.xcodeproj/project.pbxproj b/AppBox.xcodeproj/project.pbxproj index 68624ecc..d8a56472 100644 --- a/AppBox.xcodeproj/project.pbxproj +++ b/AppBox.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + E15C266A1D7FD5CE004243B9 /* ShowLinkViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E15C26691D7FD5CE004243B9 /* ShowLinkViewController.m */; }; E16437D41D743A4E00CE8B7E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E16437D31D743A4E00CE8B7E /* AppDelegate.m */; }; E16437D71D743A4E00CE8B7E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E16437D61D743A4E00CE8B7E /* main.m */; }; E16437DD1D743A4E00CE8B7E /* AppBox.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = E16437DB1D743A4E00CE8B7E /* AppBox.xcdatamodeld */; }; @@ -50,6 +51,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + E15C26681D7FD5CE004243B9 /* ShowLinkViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShowLinkViewController.h; sourceTree = ""; }; + E15C26691D7FD5CE004243B9 /* ShowLinkViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShowLinkViewController.m; sourceTree = ""; }; E16437CF1D743A4E00CE8B7E /* AppBox.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AppBox.app; sourceTree = BUILT_PRODUCTS_DIR; }; E16437D21D743A4E00CE8B7E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; E16437D31D743A4E00CE8B7E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -100,6 +103,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + E15C26671D7FD5A9004243B9 /* ShowLinkViewController */ = { + isa = PBXGroup; + children = ( + E15C26681D7FD5CE004243B9 /* ShowLinkViewController.h */, + E15C26691D7FD5CE004243B9 /* ShowLinkViewController.m */, + ); + path = ShowLinkViewController; + sourceTree = ""; + }; E16437C61D743A4E00CE8B7E = { isa = PBXGroup; children = ( @@ -146,6 +158,7 @@ children = ( E16437ED1D743ABE00CE8B7E /* Storyboard */, E16437F01D743B3600CE8B7E /* HomeViewController */, + E15C26671D7FD5A9004243B9 /* ShowLinkViewController */, ); path = ViewController; sourceTree = ""; @@ -305,6 +318,7 @@ E16437D71D743A4E00CE8B7E /* main.m in Sources */, E16437D41D743A4E00CE8B7E /* AppDelegate.m in Sources */, E1CFC65E1D7E7FEA005872BE /* Common.m in Sources */, + E15C266A1D7FD5CE004243B9 /* ShowLinkViewController.m in Sources */, E188EA111D78485900EBCA52 /* GooglURLShortenerService.m in Sources */, E16437F31D743B6800CE8B7E /* HomeViewController.m in Sources */, E188EA101D78485900EBCA52 /* BitlyURLShortenerService.m in Sources */, @@ -422,6 +436,7 @@ INFOPLIST_FILE = AppBox/Info.plist; LD_DYLIB_INSTALL_NAME = ""; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_BUNDLE_IDENTIFIER = com.developerinsider.AppBox; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -442,6 +457,7 @@ INFOPLIST_FILE = AppBox/Info.plist; LD_DYLIB_INSTALL_NAME = ""; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_BUNDLE_IDENTIFIER = com.developerinsider.AppBox; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/AppBox/Base.lproj/Main.storyboard b/AppBox/Base.lproj/Main.storyboard index fc727559..36c7add1 100644 --- a/AppBox/Base.lproj/Main.storyboard +++ b/AppBox/Base.lproj/Main.storyboard @@ -148,7 +148,10 @@ - + + + + @@ -156,7 +159,7 @@ - + @@ -164,7 +167,7 @@ - + @@ -203,7 +206,7 @@ - + @@ -221,19 +224,19 @@ - + - + - + - + - + @@ -248,12 +251,12 @@ - + - + @@ -307,6 +310,8 @@ + + @@ -400,9 +405,9 @@ - + diff --git a/AppBox/Info.plist b/AppBox/Info.plist index fedf893d..03e9cc8f 100644 --- a/AppBox/Info.plist +++ b/AppBox/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 0.2 CFBundleSignature ???? CFBundleURLTypes diff --git a/AppBox/ViewController/HomeViewController/HomeViewController.h b/AppBox/ViewController/HomeViewController/HomeViewController.h index 603c5679..ce65838a 100644 --- a/AppBox/ViewController/HomeViewController/HomeViewController.h +++ b/AppBox/ViewController/HomeViewController/HomeViewController.h @@ -13,6 +13,7 @@ #import "Common.h" #import "Tiny.h" #import "GooglURLShortenerService.h" +#import "ShowLinkViewController.h" typedef enum : NSUInteger { FileTypeIPA, @@ -21,17 +22,21 @@ typedef enum : NSUInteger { @interface HomeViewController : NSViewController { DBRestClient *restClient; + IBOutlet NSTextField *labelIPAName; + IBOutlet NSButton *buttonSelectIPAFile; + IBOutlet NSButton *buttonLinkWithDropbox; + + IBOutlet NSButton *buttonShutdownMac; + IBOutlet NSTextField *textFieldEmail; + IBOutlet NSTextField *textFieldEmailSubject; + IBOutlet NSTextView *textViewEmailContent; + + + IBOutlet NSTextField *labelStatus; + IBOutlet NSView *viewProgressStatus; + IBOutlet NSProgressIndicator *progressIndicator; } -@property (weak) IBOutlet NSButton *buttonLinkWithDropbox; -@property (weak) IBOutlet NSButton *buttonSelectIPAFile; -@property (weak) IBOutlet NSTextField *labelIPAName; -@property (weak) IBOutlet NSProgressIndicator *progressIndicator; -@property (weak) IBOutlet NSTextField *labelStatus; -@property (weak) IBOutlet NSView *viewProgressStatus; -@property (weak) IBOutlet NSTextField *textFieldEmail; -@property (weak) IBOutlet NSTextField *textFieldEmailSubject; -@property (unsafe_unretained) IBOutlet NSTextView *textViewEmailContent; - (DBRestClient *)restClient; diff --git a/AppBox/ViewController/HomeViewController/HomeViewController.m b/AppBox/ViewController/HomeViewController/HomeViewController.m index 58c52eeb..54fce9a7 100644 --- a/AppBox/ViewController/HomeViewController/HomeViewController.m +++ b/AppBox/ViewController/HomeViewController/HomeViewController.m @@ -15,6 +15,7 @@ @implementation HomeViewController{ NSString *ipaFileDBURL; NSString *manifestFileDBURL; NSDictionary *manifestData; + NSURL *appShortSharedURL; __block NSDictionary *ipaInfoPlist; } @@ -71,17 +72,32 @@ - (IBAction)buttonSelectIPAFileTapped:(NSButton *)sender { uuid = [Common generateUUID]; //Set progress started view state [self progressStartedViewState]; - self.labelIPAName.stringValue = ipaFileURL.lastPathComponent; + labelIPAName.stringValue = ipaFileURL.lastPathComponent; NSString *fromPath = [[ipaFileURL.absoluteString substringFromIndex:7] stringByReplacingOccurrencesOfString:@"%20" withString:@" "]; //Unzip ipa + __block NSString *payloadEntry; + __block NSString *infoPlistPath; [SSZipArchive unzipFileAtPath:fromPath toDestination:NSTemporaryDirectory() overwrite:YES password:nil progressHandler:^(NSString * _Nonnull entry, unz_file_info zipInfo, long entryNumber, long total) { + if ([[entry.lastPathComponent substringFromIndex:(entry.lastPathComponent.length-4)].lowercaseString isEqualToString: @".app"]) { + payloadEntry = entry; + } + if ([[entry lastPathComponent].lowercaseString isEqualToString:@"info.plist"]) { + infoPlistPath = entry; + } NSLog(@"Extracting file %@-%@",[NSNumber numberWithLong:entryNumber], [NSNumber numberWithLong:total]); } completionHandler:^(NSString * _Nonnull path, BOOL succeeded, NSError * _Nonnull error) { - NSString *payloadPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"payload/%@app/Info.plist",[ipaFileURL.lastPathComponent substringToIndex:ipaFileURL.lastPathComponent.length-3]]]; + if (error) { + [Common showAlertWithTitle:@"AppBox - Error" andMessage:error.localizedDescription]; + return; + } //get info.plist - ipaInfoPlist = [NSDictionary dictionaryWithContentsOfFile:payloadPath]; + ipaInfoPlist = [NSDictionary dictionaryWithContentsOfFile:[NSTemporaryDirectory() stringByAppendingPathComponent:infoPlistPath]]; + if (ipaInfoPlist == nil) { + [Common showAlertWithTitle:@"AppBox - Error" andMessage:@"AppBox can't able to find Info.plist in you IPA."]; + return; + } NSLog(@"ipaInfo - %@", ipaInfoPlist); //upload ipa @@ -105,18 +121,18 @@ -(void)restClient:(DBRestClient *)client uploadFileFailedWithError:(NSError *)er -(void)restClient:(DBRestClient *)client uploadedFile:(NSString *)destPath from:(NSString *)srcPath metadata:(DBMetadata *)metadata{ [restClient loadSharableLinkForFile:[NSString stringWithFormat:@"%@/%@",[self getDBDirForThisVersion],metadata.filename] shortUrl:NO]; - self.labelStatus.stringValue = [NSString stringWithFormat:@"Creating Sharable Link for %@",(fileType == FileTypeIPA)?@"IPA":@"Manifest"]; + labelStatus.stringValue = [NSString stringWithFormat:@"Creating Sharable Link for %@",(fileType == FileTypeIPA)?@"IPA":@"Manifest"]; [Common showLocalNotificationWithTitle:@"AppBox" andMessage:[NSString stringWithFormat:@"%@ file uploaded.",(fileType == FileTypeIPA)?@"IPA":@"Manifest"]]; } -(void)restClient:(DBRestClient *)client uploadProgress:(CGFloat)progress forFile:(NSString *)destPath from:(NSString *)srcPath{ if (fileType == FileTypeIPA) { - self.progressIndicator.doubleValue = progress; - self.labelStatus.stringValue = [NSString stringWithFormat:@"Uploading IPA (%@%%)",[NSNumber numberWithInt:progress * 100]]; + progressIndicator.doubleValue = progress; + labelStatus.stringValue = [NSString stringWithFormat:@"Uploading IPA (%@%%)",[NSNumber numberWithInt:progress * 100]]; NSLog(@"ipa upload progress %@",[NSNumber numberWithFloat:progress]); }else if (fileType == FileTypeManifest){ - self.progressIndicator.doubleValue = progress; - self.labelStatus.stringValue = [NSString stringWithFormat:@"Uploading Manifest (%@%%)",[NSNumber numberWithInt:progress * 100]]; + progressIndicator.doubleValue = progress; + labelStatus.stringValue = [NSString stringWithFormat:@"Uploading Manifest (%@%%)",[NSNumber numberWithInt:progress * 100]]; NSLog(@"manifest upload progress %@",[NSNumber numberWithFloat:progress]); } } @@ -135,15 +151,18 @@ -(void)restClient:(DBRestClient *)restClient loadedSharableLink:(NSString *)link NSString *shareableLink = [link substringToIndex:link.length-5]; NSLog(@"manifest link - %@",shareableLink); NSString *requiredLink = [shareableLink componentsSeparatedByString:@"dropbox.com"][1]; + + //create short url GooglURLShortenerService *service = [GooglURLShortenerService serviceWithAPIKey:@"AIzaSyD5c0jmblitp5KMZy2crCbueTU-yB1jMqI"]; [Tiny shortenURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.developerinsider.in/assets/pages/iOSDistribution.html?url=%@",requiredLink]] withService:service completion:^(NSURL *shortURL, NSError *error) { NSLog(@"Short URL - %@", shortURL); - [[NSPasteboard generalPasteboard] clearContents]; - [[NSPasteboard generalPasteboard] setString:shortURL.absoluteString forType:NSStringPboardType]; - [Common showLocalNotificationWithTitle:@"AppBox" andMessage:@"We've copy distribution link to your clipboard."]; - if (self.textFieldEmail.stringValue.length > 0) { - [Common sendEmailToAddress:self.textFieldEmail.stringValue withSubject:self.textFieldEmailSubject.stringValue andBody:[NSString stringWithFormat:@"%@\n\n%@\n\n---\n%@",self.textViewEmailContent.string,shortURL.absoluteString,@"Build generated and distributed by AppBox - http://bit.ly/GetAppBox"]]; + appShortSharedURL = shortURL; + if (textFieldEmail.stringValue.length > 0) { + [Common sendEmailToAddress:textFieldEmail.stringValue withSubject:textFieldEmailSubject.stringValue andBody:[NSString stringWithFormat:@"%@\n\n%@\n\n---\n%@",textViewEmailContent.string,shortURL.absoluteString,@"Build generated and distributed by AppBox - http://bit.ly/GetAppBox"]]; } + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSegueWithIdentifier:@"ShowLink" sender:self]; + }); [self progressCompletedViewState]; }]; } @@ -172,13 +191,13 @@ - (DBRestClient *)restClient { #pragma mark - Controller Helper - (void)updateDropBoxLinkButton{ if ([[DBSession sharedSession] isLinked]) { - self.buttonSelectIPAFile.enabled = YES; - self.buttonLinkWithDropbox.title = @"Unlink Dropbox"; + buttonSelectIPAFile.enabled = YES; + buttonLinkWithDropbox.title = @"Unlink Dropbox"; [self restClient]; } else { - self.buttonSelectIPAFile.enabled = NO; - self.buttonLinkWithDropbox.title = @"Link Dropbox"; - self.buttonLinkWithDropbox.state = [[DBAuthHelperOSX sharedHelper] isLoading] ? NSOffState : NSOnState; + buttonSelectIPAFile.enabled = NO; + buttonLinkWithDropbox.title = @"Link Dropbox"; + buttonLinkWithDropbox.state = [[DBAuthHelperOSX sharedHelper] isLoading] ? NSOffState : NSOnState; } } @@ -215,21 +234,45 @@ -(NSString *)getDBDirForThisVersion{ -(void)progressCompletedViewState{ - self.labelStatus.hidden = YES; - self.labelIPAName.hidden = YES; - self.progressIndicator.hidden = YES; - self.viewProgressStatus.hidden = YES; - self.buttonSelectIPAFile.enabled = YES; - self.buttonLinkWithDropbox.enabled = YES; + labelStatus.hidden = YES; + labelIPAName.hidden = YES; + progressIndicator.hidden = YES; + viewProgressStatus.hidden = YES; + + //button + buttonSelectIPAFile.enabled = YES; + buttonLinkWithDropbox.enabled = YES; + buttonShutdownMac.enabled = YES; + + //email + textFieldEmail.enabled = YES; + textFieldEmailSubject.enabled = YES; + textViewEmailContent.editable = YES; } -(void)progressStartedViewState{ - self.labelStatus.hidden = NO; - self.labelIPAName.hidden = NO; - self.progressIndicator.hidden = NO; - self.viewProgressStatus.hidden = NO; - self.buttonSelectIPAFile.enabled = NO; - self.buttonLinkWithDropbox.enabled = NO; + //label + labelStatus.hidden = NO; + labelIPAName.hidden = NO; + progressIndicator.hidden = NO; + viewProgressStatus.hidden = NO; + + //button + buttonSelectIPAFile.enabled = NO; + buttonLinkWithDropbox.enabled = NO; + buttonShutdownMac.enabled = NO; + + //email + textFieldEmail.enabled = NO; + textFieldEmailSubject.enabled = NO; + textViewEmailContent.editable = NO; +} + +#pragma mark - Navigation +-(void)prepareForSegue:(NSStoryboardSegue *)segue sender:(id)sender{ + if ([segue.destinationController isKindOfClass:[ShowLinkViewController class]]) { + ((ShowLinkViewController *)segue.destinationController).appLink = appShortSharedURL.absoluteString; + } } diff --git a/AppBox/ViewController/ShowLinkViewController/ShowLinkViewController.m b/AppBox/ViewController/ShowLinkViewController/ShowLinkViewController.m index b5323798..96465a6f 100644 --- a/AppBox/ViewController/ShowLinkViewController/ShowLinkViewController.m +++ b/AppBox/ViewController/ShowLinkViewController/ShowLinkViewController.m @@ -16,14 +16,10 @@ @implementation ShowLinkViewController - (void)viewDidLoad { [super viewDidLoad]; - // Do view setup here. -} - --(void) viewWillAppear{ - [super viewWillAppear]; textFieldAppLink.stringValue = self.appLink; } + - (IBAction)buttonCopyToClipboardTapped:(NSButton *)sender { [[NSPasteboard generalPasteboard] clearContents]; [[NSPasteboard generalPasteboard] setString:self.appLink forType:NSStringPboardType];