]> git.r.bdr.sh - rbdr/lyricli/commitdiff
Add Catalina support, don't auto-open apps
authorBen Beltran <redacted>
Tue, 10 Mar 2020 02:28:13 +0000 (21:28 -0500)
committerBen Beltran <redacted>
Tue, 10 Mar 2020 02:28:13 +0000 (21:28 -0500)
Sources/lyricli/sources/itunes_source.swift
Sources/lyricli/sources/spotify_source.swift

index 4e175c104c696c4fc5dd7c91c72b9d06926f9bb5..92b99695d81f590bbf22c9f117bc6e8f9ff976cf 100644 (file)
@@ -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"
+    }
+
 }
index 2cd66f53bf35ba012e157fa446ce935cc1770c99..9c516c4d4e96b550e3967f960cccbb51cbb19ad0 100644 (file)
@@ -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 {