Skip to content

Commit

Permalink
hopefully real fix for lyrics not appearing
Browse files Browse the repository at this point in the history
  • Loading branch information
whoeevee committed Aug 7, 2024
1 parent f61eeff commit 83dd32e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Sources/EeveeSpotify/DataLoaderServiceHooks.x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SPTDataLoaderServiceHook: ClassHook<NSObject> {
orig.URLSession(
session,
dataTask: task,
didReceiveData: try getCurrentTrackLyricsData(
didReceiveData: try getLyricsForCurrentTrack(
originalLyrics: try? Lyrics(serializedData: buffer)
)
)
Expand Down Expand Up @@ -90,7 +90,7 @@ class SPTDataLoaderServiceHook: ClassHook<NSObject> {
)!

do {
let lyricsData = try getCurrentTrackLyricsData()
let lyricsData = try getLyricsForCurrentTrack()

orig.URLSession(
session,
Expand Down
72 changes: 52 additions & 20 deletions Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import Orion
import SwiftUI

class SPTPlayerTrackHook: ClassHook<NSObject> {
static let targetName = "SPTPlayerTrack"

func metadata() -> [String:String] {
var meta = orig.metadata()

meta["has_lyrics"] = "true"
return meta
}
}

class LyricsScrollProviderHook: ClassHook<NSObject> {

static var targetName: String {
Expand Down Expand Up @@ -42,6 +53,7 @@ class LyricsFullscreenViewControllerHook: ClassHook<UIViewController> {

//

private var preloadedLyrics: Lyrics? = nil
private var lastLyricsState = LyricsLoadingState()

private var hasShownRestrictedPopUp = false
Expand Down Expand Up @@ -127,8 +139,9 @@ class LyricsOnlyViewControllerHook: ClassHook<UIViewController> {
}
}

func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data {

//

private func loadLyricsForCurrentTrack() throws {
guard let track = HookedInstances.currentTrack else {
throw LyricsError.NoCurrentTrack
}
Expand Down Expand Up @@ -217,28 +230,47 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data {
lastLyricsState.wasRomanized = lyricsDto.romanization == .romanized
|| (lyricsDto.romanization == .canBeRomanized && UserDefaults.lyricsOptions.romanization)

lastLyricsState.loadedSuccessfully = true
NSLog("eevee doooo")
let lyrics = Lyrics.with {
$0.colors = getLyricsColors()
$0.data = lyricsDto.toLyricsData(source: source.description)
}

preloadedLyrics = lyrics
}

return try lyrics.serializedData()
func getLyricsForCurrentTrack(originalLyrics: Lyrics? = nil) throws -> Data {
guard let track = HookedInstances.currentTrack else {
throw LyricsError.NoCurrentTrack
}

func getLyricsColors() -> LyricsColors {
let lyricsColorsSettings = UserDefaults.lyricsColors

if lyricsColorsSettings.displayOriginalColors, let originalLyrics = originalLyrics {
return originalLyrics.colors
}

return LyricsColors.with {
$0.backgroundColor = lyricsColorsSettings.useStaticColor
? Color(hex: lyricsColorsSettings.staticColor).uInt32
: Color(hex: track.extractedColorHex())
.normalized(lyricsColorsSettings.normalizationFactor)
.uInt32
$0.lineColor = Color.black.uInt32
$0.activeLineColor = Color.white.uInt32
}
var lyrics = preloadedLyrics

if lyrics == nil {
try loadLyricsForCurrentTrack()
lyrics = preloadedLyrics
}

guard var lyrics = lyrics else {
throw LyricsError.UnknownError
}

let lyricsColorsSettings = UserDefaults.lyricsColors

if lyricsColorsSettings.displayOriginalColors, let originalLyrics = originalLyrics {
lyrics.colors = originalLyrics.colors
}

lyrics.colors = LyricsColors.with {
$0.backgroundColor = lyricsColorsSettings.useStaticColor
? Color(hex: lyricsColorsSettings.staticColor).uInt32
: Color(hex: track.extractedColorHex())
.normalized(lyricsColorsSettings.normalizationFactor)
.uInt32
$0.lineColor = Color.black.uInt32
$0.activeLineColor = Color.white.uInt32
}

preloadedLyrics = nil
return try lyrics.serializedData()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ struct LyricsLoadingState {
var wasRomanized = false
var areEmpty = false
var fallbackError: LyricsError? = nil
var loadedSuccessfully = false
}

0 comments on commit 83dd32e

Please sign in to comment.