Update send to feature to send to TV app on 10.15.
This commit is contained in:
9 files changed
+112
-77
No files matched your search
@@ -38,6 +38,8 @@ final class DocumentController : NSDocumentController {
|
||||
@NSApplicationMain
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
@IBOutlet weak var sendToExternalApp: NSMenuItem!
|
||||
|
||||
private static func appSupportURL() -> URL {
|
||||
let fileManager = FileManager.default
|
||||
if let url = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask)
|
||||
@@ -156,6 +158,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
if UserDefaults.standard.bool(forKey: "SBShowQueueWindow") {
|
||||
QueueController.shared.showWindow(self)
|
||||
}
|
||||
|
||||
if #available(macOS 10.15, *) {
|
||||
sendToExternalApp.title = NSLocalizedString("Send to TV", comment: "Send to tv app menu item")
|
||||
}
|
||||
}
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
|
||||
@@ -254,16 +254,8 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
|
||||
// MARK: Actions
|
||||
|
||||
@IBAction func sendToExternalApp(_ sender: Any) {
|
||||
|
||||
if let filePath = doc.fileURL?.path, let script = NSAppleScript(source: """
|
||||
tell application "iTunes" to add (POSIX file "\(filePath)")
|
||||
""") {
|
||||
|
||||
let result = automationConsent(bundleIdentifier: "com.apple.iTunes", promptIfNeeded: true)
|
||||
if result == .granted {
|
||||
var error: NSDictionary?
|
||||
script.executeAndReturnError(&error)
|
||||
}
|
||||
if let fileURL = doc.fileURL {
|
||||
_ = sendToFileExternalApp(fileURL: fileURL)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,16 +138,29 @@ final public class TheTVDBService {
|
||||
|
||||
public var languages: [String] {
|
||||
get {
|
||||
if let result = savedLanguages, result.data.isEmpty == false {
|
||||
return result.data
|
||||
}
|
||||
else if let result = fetchLanguages() {
|
||||
savedLanguages = result
|
||||
UserDefaults.standard.set(result.data, forKey: "SBTheTVBDLanguagesArray")
|
||||
UserDefaults.standard.set(result.timestamp, forKey: "SBTheTVBDLanguagesArrayTimestamp")
|
||||
return result.data
|
||||
}
|
||||
return ["en"]
|
||||
return ["en",
|
||||
"sv",
|
||||
"no",
|
||||
"da",
|
||||
"fi",
|
||||
"nl",
|
||||
"de",
|
||||
"it",
|
||||
"es",
|
||||
"fr",
|
||||
"pl",
|
||||
"hu",
|
||||
"el",
|
||||
"tr",
|
||||
"ru",
|
||||
"he",
|
||||
"ja",
|
||||
"pt",
|
||||
"zh",
|
||||
"cs",
|
||||
"sl",
|
||||
"hr",
|
||||
"ko"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import MP42Foundation
|
||||
|
||||
final class OptionsViewController: NSViewController, NSMenuItemValidation {
|
||||
|
||||
@IBOutlet weak var sendToExternalApp: NSButton!
|
||||
@IBOutlet var destButton: NSPopUpButton!
|
||||
|
||||
@objc private dynamic let options: QueuePreferences
|
||||
@@ -59,19 +60,9 @@ final class OptionsViewController: NSViewController, NSMenuItemValidation {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Hack to fix crappy anti-aliasing on Yosemite
|
||||
// unfortunately it fixes the checkboxes anti-aliasing,
|
||||
// but break the popup buttons one…
|
||||
view.wantsLayer = true
|
||||
|
||||
for subview in view.subviews {
|
||||
if let button = subview as? NSButton {
|
||||
button.attributedTitle = NSAttributedString(string: button.title,
|
||||
attributes: [NSAttributedString.Key.foregroundColor: NSColor.labelColor,
|
||||
NSAttributedString.Key.font: NSFont.labelFont(ofSize: 11)])
|
||||
|
||||
}
|
||||
|
||||
if #available(macOS 10.15, *) {
|
||||
sendToExternalApp.title = NSLocalizedString("Send to TV", comment: "Send to tv app menu item")
|
||||
}
|
||||
|
||||
// Observe the providers changes
|
||||
|
||||
@@ -593,20 +593,7 @@ class QueueSendToiTunesAction: NSObject, QueueActionProtocol {
|
||||
override init() {}
|
||||
|
||||
func runAction(_ item: QueueItem) -> Bool {
|
||||
|
||||
if let script = NSAppleScript(source: """
|
||||
tell application "iTunes" to add (POSIX file "\(item.destURL.path)")
|
||||
""") {
|
||||
|
||||
let result = automationConsent(bundleIdentifier: "com.apple.iTunes", promptIfNeeded: true)
|
||||
if result == .granted {
|
||||
var error: NSDictionary?
|
||||
script.executeAndReturnError(&error)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return sendToFileExternalApp(fileURL: item.destURL)
|
||||
}
|
||||
|
||||
func encode(with aCoder: NSCoder) {}
|
||||
|
||||
@@ -28,6 +28,11 @@ func automationConsent(bundleIdentifier: String, promptIfNeeded: Bool) -> Privac
|
||||
if #available(macOS 10.14, *) {
|
||||
bundleIdentifier.withCString { (identifier) in
|
||||
var addressDesc = AEAddressDesc()
|
||||
|
||||
// Mare sure the target is running, if not the consent alert will not be shown.
|
||||
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier, options: [],
|
||||
additionalEventParamDescriptor: nil, launchIdentifier: nil)
|
||||
|
||||
let createDescResult = AECreateDesc(typeApplicationBundleID, identifier, strlen(identifier), &addressDesc)
|
||||
if createDescResult == noErr {
|
||||
let appleScriptPermission = AEDeterminePermissionToAutomateTarget(&addressDesc, typeWildCard, typeWildCard, promptIfNeeded)
|
||||
@@ -52,3 +57,35 @@ func automationConsent(bundleIdentifier: String, promptIfNeeded: Bool) -> Privac
|
||||
return .granted
|
||||
}
|
||||
}
|
||||
|
||||
func sendToFileExternalApp(fileURL: URL) -> Bool {
|
||||
let filePath = fileURL.path
|
||||
|
||||
if #available(macOS 10.15, *) {
|
||||
if let script = NSAppleScript(source: """
|
||||
tell application "TV" to add (POSIX file "\(filePath)")
|
||||
""") {
|
||||
|
||||
let result = automationConsent(bundleIdentifier: "com.apple.TV", promptIfNeeded: true)
|
||||
if result == .granted {
|
||||
var error: NSDictionary?
|
||||
script.executeAndReturnError(&error)
|
||||
return error != nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let script = NSAppleScript(source: """
|
||||
tell application "iTunes" to add (POSIX file "\(filePath)")
|
||||
""") {
|
||||
|
||||
let result = automationConsent(bundleIdentifier: "com.apple.iTunes", promptIfNeeded: true)
|
||||
if result == .granted {
|
||||
var error: NSDictionary?
|
||||
script.executeAndReturnError(&error)
|
||||
return error != nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user