Switch from ApplicationSpecifier to UserApp.
This commit is contained in:
parent
fd7c6d07ac
commit
bbf2b8f130
|
@ -19,49 +19,3 @@ protocol SendToCommand {
|
|||
func sendObject(_ object: Any?, selectedText: String?)
|
||||
}
|
||||
|
||||
|
||||
final class ApplicationSpecifier {
|
||||
|
||||
let bundleID: String
|
||||
var icon: NSImage? = nil
|
||||
var existsOnDisk = false
|
||||
var path: String? = nil
|
||||
|
||||
init(bundleID: String) {
|
||||
|
||||
self.bundleID = bundleID
|
||||
update()
|
||||
}
|
||||
|
||||
func update() {
|
||||
|
||||
path = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleID)
|
||||
if let path = path {
|
||||
if icon == nil {
|
||||
icon = NSWorkspace.shared.icon(forFile: path)
|
||||
}
|
||||
existsOnDisk = true
|
||||
}
|
||||
else {
|
||||
existsOnDisk = false
|
||||
icon = nil
|
||||
}
|
||||
}
|
||||
|
||||
func launch() -> Bool {
|
||||
|
||||
guard existsOnDisk, let path = path else {
|
||||
return false
|
||||
}
|
||||
|
||||
let url = URL(fileURLWithPath: path)
|
||||
if let runningApplication = try? NSWorkspace.shared.launchApplication(at: url, options: [.withErrorPresentation], configuration: [:]) {
|
||||
if runningApplication.isFinishedLaunching {
|
||||
return true
|
||||
}
|
||||
sleep(3) // Give the app time to launch. This is ugly.
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
import Cocoa
|
||||
import Data
|
||||
import RSCore
|
||||
|
||||
// Not undoable.
|
||||
|
||||
|
@ -19,11 +20,11 @@ final class SendToMicroBlogCommand: SendToCommand {
|
|||
return microBlogApp.icon
|
||||
}
|
||||
|
||||
private let microBlogApp = ApplicationSpecifier(bundleID: "blog.micro.mac")
|
||||
private let microBlogApp = UserApp(bundleID: "blog.micro.mac")
|
||||
|
||||
func canSendObject(_ object: Any?, selectedText: String?) -> Bool {
|
||||
|
||||
microBlogApp.update()
|
||||
microBlogApp.updateStatus()
|
||||
guard microBlogApp.existsOnDisk, let article = (object as? ArticlePasteboardWriter)?.article, let _ = article.preferredLink else {
|
||||
return false
|
||||
}
|
||||
|
@ -39,7 +40,7 @@ final class SendToMicroBlogCommand: SendToCommand {
|
|||
guard let article = (object as? ArticlePasteboardWriter)?.article else {
|
||||
return
|
||||
}
|
||||
guard microBlogApp.existsOnDisk, microBlogApp.launch() else {
|
||||
guard microBlogApp.launchIfNeeded(), microBlogApp.bringToFront() else {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue