From 78b2bb9eeaa0a38372b76a695077bf32582574c9 Mon Sep 17 00:00:00 2001 From: Nate West Date: Thu, 28 Jan 2016 10:00:43 -0500 Subject: [PATCH 1/3] Track exit status in the task --- app/CocoaPods/CLI Integrations/CPCLITask.h | 3 +++ app/CocoaPods/CLI Integrations/CPCLITask.m | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/CocoaPods/CLI Integrations/CPCLITask.h b/app/CocoaPods/CLI Integrations/CPCLITask.h index e037397e..118ecc45 100644 --- a/app/CocoaPods/CLI Integrations/CPCLITask.h +++ b/app/CocoaPods/CLI Integrations/CPCLITask.h @@ -56,4 +56,7 @@ /// Appends `--verbose` to the end of the command, defaults to NO @property (nonatomic, assign) BOOL verboseOutput; +/// If the task is done and successful, returns YES, otherwise NO +- (BOOL)finishedSuccessfully; + @end diff --git a/app/CocoaPods/CLI Integrations/CPCLITask.m b/app/CocoaPods/CLI Integrations/CPCLITask.m index 41fc9b5a..d23860c2 100644 --- a/app/CocoaPods/CLI Integrations/CPCLITask.m +++ b/app/CocoaPods/CLI Integrations/CPCLITask.m @@ -14,6 +14,8 @@ @interface CPCLITask () @property (nonatomic) NSProgress *progress; @property (nonatomic, copy) NSAttributedString *output; @property (nonatomic, assign) BOOL running; +@property (nonatomic, assign) int terminationStatus; + @end @implementation CPCLITask @@ -30,6 +32,7 @@ - (instancetype)initWithUserProject:(CPUserProject *)userProject self.command = command; self.delegate = delegate; self.qualityOfService = qualityOfService; + self.terminationStatus = 1; } return self; @@ -150,6 +153,8 @@ - (void)taskDidFinish completionNotification.subtitle = [[self.userProject.fileURL relativePath] stringByAbbreviatingWithTildeInPath]; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:completionNotification]; + self.terminationStatus = self.task.terminationStatus; + // Setting to `nil` signals through bindings that task has finished. self.task = nil; @@ -162,6 +167,11 @@ - (void)taskDidFinish } } +- (BOOL)finishedSuccessfully +{ + return self.terminationStatus == 0; +} + #pragma mark - Utilities static NSAttributedString *ANSIUnescapeString(NSString *input) From a6a722a27fbbd6c3976b058c54590f3894bdfd7e Mon Sep 17 00:00:00 2001 From: Nate West Date: Fri, 29 Jan 2016 11:23:36 -0500 Subject: [PATCH 2/3] Move task notifications up a level and only broadcast if notify is set --- app/CocoaPods/CLI Integrations/CPCLITask.m | 5 +--- app/CocoaPods/CPInstallAction.swift | 23 ++++++++++++++++++- app/CocoaPods/CPPodfileViewController.swift | 2 +- .../Supporting Files/Localizable.strings | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/CocoaPods/CLI Integrations/CPCLITask.m b/app/CocoaPods/CLI Integrations/CPCLITask.m index d23860c2..c7d83e0a 100644 --- a/app/CocoaPods/CLI Integrations/CPCLITask.m +++ b/app/CocoaPods/CLI Integrations/CPCLITask.m @@ -148,10 +148,7 @@ - (void)taskDidFinish name:NSFileHandleDataAvailableNotification object:nil]; - NSUserNotification *completionNotification = [[NSUserNotification alloc] init]; - completionNotification.title = NSLocalizedString(@"WORKSPACE_GENERATED_NOTIFICATION_TITLE", nil); - completionNotification.subtitle = [[self.userProject.fileURL relativePath] stringByAbbreviatingWithTildeInPath]; - [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:completionNotification]; + self.terminationStatus = self.task.terminationStatus; diff --git a/app/CocoaPods/CPInstallAction.swift b/app/CocoaPods/CPInstallAction.swift index 0c5b9ee9..0a24a409 100644 --- a/app/CocoaPods/CPInstallAction.swift +++ b/app/CocoaPods/CPInstallAction.swift @@ -7,11 +7,13 @@ enum InstallActionType { class CPInstallAction: NSObject, CPCLITaskDelegate { let userProject: CPUserProject + let notify: Bool dynamic var taskAttributedString: NSAttributedString? dynamic var task: CPCLITask? - init(userProject: CPUserProject) { + init(userProject: CPUserProject, notify: Bool) { self.userProject = userProject + self.notify = notify } func performAction(type: InstallActionType) { @@ -34,4 +36,23 @@ class CPInstallAction: NSObject, CPCLITaskDelegate { func task(task: CPCLITask!, didUpdateOutputContents updatedOutput: NSAttributedString!) { self.taskAttributedString = updatedOutput } + + func taskCompleted(task: CPCLITask!) { + if (notify) { + if task.finishedSuccessfully() { + notifyWithTitle(NSLocalizedString("WORKSPACE_GENERATED_NOTIFICATION_TITLE", comment: "")) + } else { + notifyWithTitle(NSLocalizedString("WORKSPACE_FAILED_GENERATION_NOTIFICATION_TITLE", comment: "")) + } + } + } + + private func notifyWithTitle(title: String) { + let notification = NSUserNotification() + notification.title = title + if let path = userProject.fileURL?.relativePath { + notification.subtitle = (path as NSString).stringByAbbreviatingWithTildeInPath + } + NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(notification) + } } diff --git a/app/CocoaPods/CPPodfileViewController.swift b/app/CocoaPods/CPPodfileViewController.swift index c46a5f7a..88b325a0 100644 --- a/app/CocoaPods/CPPodfileViewController.swift +++ b/app/CocoaPods/CPPodfileViewController.swift @@ -20,7 +20,7 @@ class CPPodfileViewController: NSViewController, NSTabViewDelegate { override func viewWillAppear() { // The userProject is DI'd in after viewDidLoad - installAction = CPInstallAction(userProject: userProject) + installAction = CPInstallAction(userProject: userProject, notify: true) // The view needs to be added to a window before we can use // the window to pull out to the document icon from the window diff --git a/app/CocoaPods/Supporting Files/Localizable.strings b/app/CocoaPods/Supporting Files/Localizable.strings index 0a3a775a..8cba000c 100644 --- a/app/CocoaPods/Supporting Files/Localizable.strings +++ b/app/CocoaPods/Supporting Files/Localizable.strings @@ -9,6 +9,7 @@ "INSTALL_CLI_WARNING_OVERWRITE" = "Overwrite"; "WORKSPACE_GENERATED_NOTIFICATION_TITLE" = "Pod Workspace Ready"; +"WORKSPACE_FAILED_GENERATION_NOTIFICATION_TITLE" = "Something Went Wrong"; "CANCEL" = "Cancel"; From 5e64e543f2cdb0cea70c8aa4093c36e7dec6a693 Mon Sep 17 00:00:00 2001 From: Nate West Date: Fri, 29 Jan 2016 11:27:46 -0500 Subject: [PATCH 3/3] Fix whitespace --- app/CocoaPods/CLI Integrations/CPCLITask.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/CocoaPods/CLI Integrations/CPCLITask.m b/app/CocoaPods/CLI Integrations/CPCLITask.m index c7d83e0a..c1a2d939 100644 --- a/app/CocoaPods/CLI Integrations/CPCLITask.m +++ b/app/CocoaPods/CLI Integrations/CPCLITask.m @@ -148,8 +148,6 @@ - (void)taskDidFinish name:NSFileHandleDataAvailableNotification object:nil]; - - self.terminationStatus = self.task.terminationStatus; // Setting to `nil` signals through bindings that task has finished.