diff --git a/Sources/EeveeSpotify/HookedInstances.x.swift b/Sources/EeveeSpotify/HookedInstances.x.swift index 54355f3..4099903 100644 --- a/Sources/EeveeSpotify/HookedInstances.x.swift +++ b/Sources/EeveeSpotify/HookedInstances.x.swift @@ -1,16 +1,16 @@ import Orion +import UIKit class HookedInstances { static var productState: SPTCoreProductState? static var currentTrack: SPTPlayerTrack? + static var nowPlayingMetaBackgroundModel: SPTNowPlayingMetadataBackgroundViewModel? } class SPTNowPlayingModelHook: ClassHook { - static let targetName = "SPTNowPlayingModel" func currentTrack() -> SPTPlayerTrack? { - if let track = orig.currentTrack() { HookedInstances.currentTrack = track return track @@ -20,12 +20,22 @@ class SPTNowPlayingModelHook: ClassHook { } } -class SPTCoreProductStateInstanceHook: ClassHook { +class SPTNowPlayingMetadataBackgroundViewModelHook: ClassHook { + static let targetName = "SPTNowPlayingMetadataBackgroundViewModel" + + func color() -> UIColor { + HookedInstances.nowPlayingMetaBackgroundModel = Dynamic.convert( + target, + to: SPTNowPlayingMetadataBackgroundViewModel.self + ) + return orig.color() + } +} +class SPTCoreProductStateInstanceHook: ClassHook { static let targetName = "SPTCoreProductState" func stringForKey(_ key: String) -> NSString { - HookedInstances.productState = Dynamic.convert( target, to: SPTCoreProductState.self diff --git a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift index 6afa600..e984f55 100644 --- a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift +++ b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift @@ -259,12 +259,21 @@ func getLyricsForCurrentTrack(originalLyrics: Lyrics? = nil) throws -> Data { lyrics.colors = originalLyrics.colors } else { + var color: Color? + + if let extractedColorHex = track.extractedColorHex() { + color = Color(hex: extractedColorHex) + } + else if let uiColor = HookedInstances.nowPlayingMetaBackgroundModel?.color() { + color = Color(uiColor) + } + + color = color?.normalized(lyricsColorsSettings.normalizationFactor) + lyrics.colors = LyricsColors.with { $0.backgroundColor = lyricsColorsSettings.useStaticColor ? Color(hex: lyricsColorsSettings.staticColor).uInt32 - : Color(hex: track.extractedColorHex()) - .normalized(lyricsColorsSettings.normalizationFactor) - .uInt32 + : color?.uInt32 ?? Color.gray.uInt32 $0.lineColor = Color.black.uInt32 $0.activeLineColor = Color.white.uInt32 } diff --git a/Sources/EeveeSpotify/Models/Headers/SPTNowPlayingMetadataBackgroundViewModel.swift b/Sources/EeveeSpotify/Models/Headers/SPTNowPlayingMetadataBackgroundViewModel.swift new file mode 100644 index 0000000..2b5fbe5 --- /dev/null +++ b/Sources/EeveeSpotify/Models/Headers/SPTNowPlayingMetadataBackgroundViewModel.swift @@ -0,0 +1,5 @@ +import UIKit + +@objc protocol SPTNowPlayingMetadataBackgroundViewModel { + func color() -> UIColor +} diff --git a/Sources/EeveeSpotify/Models/Headers/SPTPlayerTrack.swift b/Sources/EeveeSpotify/Models/Headers/SPTPlayerTrack.swift index 244f86a..19e2b4f 100644 --- a/Sources/EeveeSpotify/Models/Headers/SPTPlayerTrack.swift +++ b/Sources/EeveeSpotify/Models/Headers/SPTPlayerTrack.swift @@ -3,7 +3,7 @@ import Foundation @objc protocol SPTPlayerTrack { func setMetadata(_ metadata: [String:String]) func metadata() -> [String:String] - func extractedColorHex() -> String + func extractedColorHex() -> String? func trackTitle() -> String func artistTitle() -> String func URI() -> SPTURL