From: Ben Beltran Date: Tue, 10 Mar 2020 02:28:13 +0000 (-0500) Subject: Add Catalina support, don't auto-open apps X-Git-Tag: 1.0.0^2^2~8 X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli/commitdiff_plain/9cf995f0faa99868b3a6204332571511e9155f9d?ds=inline;hp=-c Add Catalina support, don't auto-open apps --- 9cf995f0faa99868b3a6204332571511e9155f9d diff --git a/Sources/lyricli/sources/itunes_source.swift b/Sources/lyricli/sources/itunes_source.swift index 4e175c1..92b9969 100644 --- a/Sources/lyricli/sources/itunes_source.swift +++ b/Sources/lyricli/sources/itunes_source.swift @@ -1,4 +1,5 @@ import ScriptingBridge +import Foundation // Protocol to obtain the track from iTunes @objc protocol iTunesTrack { @@ -20,7 +21,12 @@ class ItunesSource: Source { // Calls the spotify API and returns the current track var currentTrack: Track? { - if let iTunes: iTunesApplication = SBApplication(bundleIdentifier: "com.apple.iTunes") { + if let iTunes: iTunesApplication = SBApplication(bundleIdentifier: bundleIdentifier) { + if let application = iTunes as? SBApplication { + if !application.isRunning { + return nil + } + } // Attempt to fetch the title from a stream if let currentStreamTitle = iTunes.currentStreamTitle { @@ -58,4 +64,14 @@ class ItunesSource: Source { return nil } + private var bundleIdentifier: String { + if ProcessInfo().isOperatingSystemAtLeast( + OperatingSystemVersion(majorVersion: 10, minorVersion: 15, patchVersion: 0) + ) { + return "com.apple.Music" + } + + return "com.apple.iTunes" + } + } diff --git a/Sources/lyricli/sources/spotify_source.swift b/Sources/lyricli/sources/spotify_source.swift index 2cd66f5..9c516c4 100644 --- a/Sources/lyricli/sources/spotify_source.swift +++ b/Sources/lyricli/sources/spotify_source.swift @@ -20,8 +20,14 @@ class SpotifySource: Source { var currentTrack: Track? { if let spotify: SpotifyApplication = SBApplication(bundleIdentifier: "com.spotify.client") { + if let application = spotify as? SBApplication { + if !application.isRunning { + return nil + } + } // Attempt to fetch the title from a song + if let currentTrack = spotify.currentTrack { if let track = currentTrack { if let name = track.name {