diff options
| author | Ben Beltran <ben@nsovocal.com> | 2020-03-09 21:28:13 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2020-03-09 21:28:13 -0500 |
| commit | 9cf995f0faa99868b3a6204332571511e9155f9d (patch) | |
| tree | 3330974714aac1cee089a1be22ed791375dea57a /Sources | |
| parent | 6a628388c496987819ef26bda1a99595bce2b1d5 (diff) | |
Add Catalina support, don't auto-open apps
Diffstat (limited to 'Sources')
| -rw-r--r-- | Sources/lyricli/sources/itunes_source.swift | 18 | ||||
| -rw-r--r-- | Sources/lyricli/sources/spotify_source.swift | 6 |
2 files changed, 23 insertions, 1 deletions
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 { |