2018-01-09 06:53:49 +01:00
|
|
|
//
|
|
|
|
// SendToMarsEditCommand.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2018-01-09 06:53:49 +01:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 1/8/18.
|
|
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
import AppKit
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2024-03-21 04:49:15 +01:00
|
|
|
import Core
|
|
|
|
import AppKitExtras
|
2018-01-09 06:53:49 +01:00
|
|
|
|
2023-06-26 01:48:37 +02:00
|
|
|
final class SendToMarsEditCommand: SendToCommand {
|
|
|
|
|
|
|
|
let title = "MarsEdit"
|
|
|
|
let image: RSImage? = AppAssets.marsEditIcon
|
2018-01-12 07:18:46 +01:00
|
|
|
|
2018-01-14 20:00:42 +01:00
|
|
|
private let marsEditApps = [UserApp(bundleID: "com.red-sweater.marsedit4"), UserApp(bundleID: "com.red-sweater.marsedit")]
|
2018-01-12 07:18:46 +01:00
|
|
|
|
2018-01-10 07:04:45 +01:00
|
|
|
func canSendObject(_ object: Any?, selectedText: String?) -> Bool {
|
2023-06-26 01:48:37 +02:00
|
|
|
appToUse() != nil
|
2018-01-09 06:53:49 +01:00
|
|
|
}
|
|
|
|
|
2024-03-20 07:05:30 +01:00
|
|
|
@MainActor func sendObject(_ object: Any?, selectedText: String?) {
|
2018-01-09 06:53:49 +01:00
|
|
|
|
2018-01-15 21:22:12 +01:00
|
|
|
guard canSendObject(object, selectedText: selectedText) else {
|
2018-01-12 07:18:46 +01:00
|
|
|
return
|
|
|
|
}
|
2018-01-15 21:22:12 +01:00
|
|
|
guard let article = (object as? ArticlePasteboardWriter)?.article else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard let app = appToUse(), app.launchIfNeeded(), app.bringToFront() else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
send(article, to: app)
|
2018-01-12 07:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension SendToMarsEditCommand {
|
|
|
|
|
2024-03-20 07:05:30 +01:00
|
|
|
@MainActor func send(_ article: Article, to app: UserApp) {
|
2018-01-15 21:22:12 +01:00
|
|
|
|
|
|
|
// App has already been launched.
|
|
|
|
|
|
|
|
guard let targetDescriptor = app.targetDescriptor() else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let body = article.contentHTML ?? article.contentText ?? article.summary
|
|
|
|
let authorName = article.authors?.first?.name
|
|
|
|
|
2024-02-26 08:12:21 +01:00
|
|
|
let sender = SendToBlogEditorApp(targetDescriptor: targetDescriptor, title: article.title, body: body, summary: article.summary, link: article.externalLink, permalink: article.link, subject: nil, creator: authorName, commentsURL: nil, guid: article.uniqueID, sourceName: article.feed?.nameForDisplay, sourceHomeURL: article.feed?.homePageURL, sourceFeedURL: article.feed?.url)
|
2018-01-15 21:22:12 +01:00
|
|
|
let _ = sender.send()
|
|
|
|
}
|
|
|
|
|
2018-01-14 20:00:42 +01:00
|
|
|
func appToUse() -> UserApp? {
|
2018-01-12 07:18:46 +01:00
|
|
|
|
2018-01-14 20:12:28 +01:00
|
|
|
marsEditApps.forEach{ $0.updateStatus() }
|
|
|
|
|
2018-01-14 20:00:42 +01:00
|
|
|
for app in marsEditApps {
|
|
|
|
if app.isRunning {
|
|
|
|
return app
|
|
|
|
}
|
2018-01-14 20:12:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for app in marsEditApps {
|
2018-01-14 20:00:42 +01:00
|
|
|
if app.existsOnDisk {
|
|
|
|
return app
|
2018-01-12 07:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-01-09 06:53:49 +01:00
|
|
|
}
|
|
|
|
}
|