From dbe5080541934d5da051b9c7595615f7f37c02fe Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Tue, 15 Oct 2019 08:34:35 +0200 Subject: [PATCH] Update send to feature to send to TV app on 10.15. --- Base.lproj/MainMenu.xib | 10 +++- Base.lproj/QueueOptions.xib | 55 ++++++++++--------- Classes/AppDelegate.swift | 6 ++ Classes/DocumentWindowController.swift | 12 +--- .../MetadataImporters/TheTVDBService.swift | 33 +++++++---- Classes/OptionsViewController.swift | 17 ++---- Classes/QueueAction.swift | 15 +---- Classes/Utilities.swift | 37 +++++++++++++ Subler.xcodeproj/project.pbxproj | 4 ++ 9 files changed, 112 insertions(+), 77 deletions(-) diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 992edd3..c66c4e2 100755 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -498,7 +498,11 @@ - + + + + + diff --git a/Base.lproj/QueueOptions.xib b/Base.lproj/QueueOptions.xib index 36be60b..1ed4b6e 100644 --- a/Base.lproj/QueueOptions.xib +++ b/Base.lproj/QueueOptions.xib @@ -1,14 +1,15 @@ - + - + + @@ -22,7 +23,7 @@ - + @@ -36,7 +37,7 @@ - + @@ -50,7 +51,7 @@ - + @@ -64,7 +65,7 @@ - + @@ -78,7 +79,7 @@ - + @@ -92,7 +93,7 @@ - + @@ -129,7 +130,7 @@ - + @@ -200,7 +201,7 @@ - + @@ -232,7 +233,7 @@ - + @@ -256,7 +257,7 @@ - + @@ -302,7 +303,7 @@ - + @@ -338,7 +339,7 @@ - + @@ -363,7 +364,7 @@ - + @@ -377,7 +378,7 @@ - + @@ -405,7 +406,7 @@ - + @@ -430,7 +431,7 @@ - + @@ -444,7 +445,7 @@ - + @@ -458,7 +459,7 @@ - + @@ -472,7 +473,7 @@ - + @@ -486,7 +487,7 @@ - + @@ -523,7 +524,7 @@ - + @@ -551,7 +552,7 @@ - + @@ -573,7 +574,7 @@ - + @@ -583,7 +584,7 @@ - + @@ -597,7 +598,7 @@ - + diff --git a/Classes/AppDelegate.swift b/Classes/AppDelegate.swift index a11c12f..0b6a2b4 100644 --- a/Classes/AppDelegate.swift +++ b/Classes/AppDelegate.swift @@ -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) { diff --git a/Classes/DocumentWindowController.swift b/Classes/DocumentWindowController.swift index e1713fe..4e1f85c 100644 --- a/Classes/DocumentWindowController.swift +++ b/Classes/DocumentWindowController.swift @@ -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) } } diff --git a/Classes/MetadataImporters/TheTVDBService.swift b/Classes/MetadataImporters/TheTVDBService.swift index fbf2cc0..793d90e 100644 --- a/Classes/MetadataImporters/TheTVDBService.swift +++ b/Classes/MetadataImporters/TheTVDBService.swift @@ -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"] } } diff --git a/Classes/OptionsViewController.swift b/Classes/OptionsViewController.swift index 7103477..64b49d6 100644 --- a/Classes/OptionsViewController.swift +++ b/Classes/OptionsViewController.swift @@ -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 diff --git a/Classes/QueueAction.swift b/Classes/QueueAction.swift index 75910e3..fd84efb 100644 --- a/Classes/QueueAction.swift +++ b/Classes/QueueAction.swift @@ -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) {} diff --git a/Classes/Utilities.swift b/Classes/Utilities.swift index 67629d6..6c2a678 100644 --- a/Classes/Utilities.swift +++ b/Classes/Utilities.swift @@ -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 +} diff --git a/Subler.xcodeproj/project.pbxproj b/Subler.xcodeproj/project.pbxproj index 63cb936..2afce11 100644 --- a/Subler.xcodeproj/project.pbxproj +++ b/Subler.xcodeproj/project.pbxproj @@ -1419,6 +1419,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1.5.18; DEVELOPMENT_TEAM = 5X9DE89KYV; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -1437,6 +1438,7 @@ "@executable_path/../Frameworks", ); LIBRARY_SEARCH_PATHS = "$(inherited)"; + MARKETING_VERSION = 1.5.18; OTHER_CFLAGS = ""; OTHER_LDFLAGS = "-Wl,-rpath,@loader_path/../Frameworks"; OTHER_SWIFT_FLAGS = ""; @@ -1460,6 +1462,7 @@ CODE_SIGN_ENTITLEMENTS = Subler.entitlements; CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1.5.18; DEVELOPMENT_TEAM = 5X9DE89KYV; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -1477,6 +1480,7 @@ "@executable_path/../Frameworks", ); LIBRARY_SEARCH_PATHS = "$(inherited)"; + MARKETING_VERSION = 1.5.18; OTHER_CFLAGS = ""; OTHER_LDFLAGS = "-Wl,-rpath,@loader_path/../Frameworks"; OTHER_SWIFT_FLAGS = "";