From 6ab534d0f3d6a18453a9ca2747e8dc38cdc20c24 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 2 Aug 2017 20:12:27 -0400 Subject: [PATCH] Show error notification if publishing fails --- writeas/ViewController.swift | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/writeas/ViewController.swift b/writeas/ViewController.swift index 8598193..9012988 100644 --- a/writeas/ViewController.swift +++ b/writeas/ViewController.swift @@ -102,17 +102,23 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe task.waitUntilExit() DispatchQueue.main.async { - var notification = NSUserNotification() - - // All these values are optional - notification.title = "Published!" - notification.informativeText = "The link is copied — press ⌘+V to share it." - notification.soundName = NSUserNotificationDefaultSoundName - if let ad = NSApplication.shared().delegate as? AppDelegate { ad.filePublishItem.isEnabled = true } + var notification = NSUserNotification() + + if task.terminationStatus == 0 { + // Successfully published + notification.title = "Published!" + notification.informativeText = "The link is copied — press ⌘+V to share it." + } else { + // Something went wrong + notification.title = "Unable to publish." + notification.informativeText = "There was a problem publishing. Please check your internet and try again." + } + notification.soundName = NSUserNotificationDefaultSoundName + NSUserNotificationCenter.default.deliver(notification) } }