Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #232 from nwest/task-exit-notification
Browse files Browse the repository at this point in the history
Pod install/update notifications for success and failure
  • Loading branch information
orta committed Jan 30, 2016
2 parents 8e1ea71 + 5e64e54 commit aea6b0a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/CocoaPods/CLI Integrations/CPCLITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 9 additions & 4 deletions app/CocoaPods/CLI Integrations/CPCLITask.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +32,7 @@ - (instancetype)initWithUserProject:(CPUserProject *)userProject
self.command = command;
self.delegate = delegate;
self.qualityOfService = qualityOfService;
self.terminationStatus = 1;
}

return self;
Expand Down Expand Up @@ -145,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;

// Setting to `nil` signals through bindings that task has finished.
self.task = nil;
Expand All @@ -162,6 +162,11 @@ - (void)taskDidFinish
}
}

- (BOOL)finishedSuccessfully
{
return self.terminationStatus == 0;
}

#pragma mark - Utilities

static NSAttributedString *ANSIUnescapeString(NSString *input)
Expand Down
23 changes: 22 additions & 1 deletion app/CocoaPods/CPInstallAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion app/CocoaPods/CPPodfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/CocoaPods/Supporting Files/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit aea6b0a

Please sign in to comment.