local files lyrics background color

This commit is contained in:
eevee
2024-08-26 19:15:21 +03:00
parent 40fccd06ac
commit 5c4d563eca
4 changed files with 32 additions and 8 deletions
+14 -4
View File
@@ -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<NSObject> {
static let targetName = "SPTNowPlayingModel"
func currentTrack() -> SPTPlayerTrack? {
if let track = orig.currentTrack() {
HookedInstances.currentTrack = track
return track
@@ -20,12 +20,22 @@ class SPTNowPlayingModelHook: ClassHook<NSObject> {
}
}
class SPTCoreProductStateInstanceHook: ClassHook<NSObject> {
class SPTNowPlayingMetadataBackgroundViewModelHook: ClassHook<NSObject> {
static let targetName = "SPTNowPlayingMetadataBackgroundViewModel"
func color() -> UIColor {
HookedInstances.nowPlayingMetaBackgroundModel = Dynamic.convert(
target,
to: SPTNowPlayingMetadataBackgroundViewModel.self
)
return orig.color()
}
}
class SPTCoreProductStateInstanceHook: ClassHook<NSObject> {
static let targetName = "SPTCoreProductState"
func stringForKey(_ key: String) -> NSString {
HookedInstances.productState = Dynamic.convert(
target,
to: SPTCoreProductState.self
@@ -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
}
@@ -0,0 +1,5 @@
import UIKit
@objc protocol SPTNowPlayingMetadataBackgroundViewModel {
func color() -> UIColor
}
@@ -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