From 17ce4fc26a4a186414e28db632c17f6190d65f1e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 8 Jan 2018 22:10:56 -0800 Subject: [PATCH] Check if the Micro.blog app exists on disk when app becomes active. --- Commands/SendToMarsEditCommand.swift | 2 +- Commands/SendToMicroBlogCommand.swift | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Commands/SendToMarsEditCommand.swift b/Commands/SendToMarsEditCommand.swift index b48662ac4..ca1e29d81 100644 --- a/Commands/SendToMarsEditCommand.swift +++ b/Commands/SendToMarsEditCommand.swift @@ -8,7 +8,7 @@ import Foundation -struct SendToMarsEditCommand { +final class SendToMarsEditCommand: SendToCommand { func canSendObject(_ object: Any?) -> Bool { diff --git a/Commands/SendToMicroBlogCommand.swift b/Commands/SendToMicroBlogCommand.swift index 1c80fc9a2..8260799dc 100644 --- a/Commands/SendToMicroBlogCommand.swift +++ b/Commands/SendToMicroBlogCommand.swift @@ -6,26 +6,37 @@ // Copyright © 2018 Ranchero Software. All rights reserved. // -import Foundation +import Cocoa // Not undoable. -struct SendToMicroBlogCommand: SendToCommand { +final class SendToMicroBlogCommand: SendToCommand { + + private let bundleID = "blog.micro.mac" + private var appExists = false + + init() { + + self.appExists = appExistsOnDisk(bundleID) + NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive(_:)), name: NSApplication.didBecomeActiveNotification, object: nil) + } func canSendObject(_ object: Any?) -> Bool { + if !appExists { + return false + } return false } func sendObject(_ object: Any?) { } -} -private extension SendToMicroBlogCommand { + @objc func appDidBecomeActive(_ note: Notification) { - func appExists() { - - + self.appExists = appExistsOnDisk(bundleID) } } + +