Make the send-to-Micro.blog command work. Need some tweaking, but it mostly does the job.

This commit is contained in:
Brent Simmons
2018-01-11 22:18:46 -08:00
parent 811084c106
commit c3bcf82713
7 changed files with 115 additions and 18 deletions

View File

@@ -13,18 +13,18 @@ import Data
final class SendToMicroBlogCommand: SendToCommand {
private let bundleID = "blog.micro.mac"
private var appExists = false
let title = NSLocalizedString("Send to Micro.blog", comment: "Send to command")
init() {
self.appExists = appExistsOnDisk(bundleID)
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive(_:)), name: NSApplication.didBecomeActiveNotification, object: nil)
var image: NSImage? {
return microBlogApp.icon
}
private let microBlogApp = ApplicationSpecifier(bundleID: "blog.micro.mac")
func canSendObject(_ object: Any?, selectedText: String?) -> Bool {
guard appExists, let article = object as? Article, let _ = article.preferredLink else {
microBlogApp.update()
guard microBlogApp.existsOnDisk, let article = (object as? ArticlePasteboardWriter)?.article, let _ = article.preferredLink else {
return false
}
@@ -36,7 +36,10 @@ final class SendToMicroBlogCommand: SendToCommand {
guard canSendObject(object, selectedText: selectedText) else {
return
}
guard let article = object as? Article else {
guard let article = (object as? ArticlePasteboardWriter)?.article else {
return
}
guard microBlogApp.existsOnDisk, microBlogApp.launch() else {
return
}
@@ -67,11 +70,6 @@ final class SendToMicroBlogCommand: SendToCommand {
let _ = try? NSWorkspace.shared.open(url, options: [], configuration: [:])
}
@objc func appDidBecomeActive(_ note: Notification) {
self.appExists = appExistsOnDisk(bundleID)
}
}