From d12d2af0cde917f031636630f769dba4c9d2cadc Mon Sep 17 00:00:00 2001 From: eevee Date: Wed, 7 Aug 2024 09:46:48 +0300 Subject: [PATCH] fix lyrics not appearing --- .../EeveeSpotify/Lyrics/CustomLyrics.x.swift | 50 +++++++++---------- .../Lyrics/Models/LyricsLoadingState.swift | 7 +++ 2 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 Sources/EeveeSpotify/Lyrics/Models/LyricsLoadingState.swift diff --git a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift index 360d10f..d76a32e 100644 --- a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift +++ b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift @@ -1,15 +1,16 @@ import Orion import SwiftUI -class SPTPlayerTrackHook: ClassHook { - - static let targetName = "SPTPlayerTrack" - - func metadata() -> [String:String] { - var meta = orig.metadata() - - meta["has_lyrics"] = "true" - return meta +class LyricsScrollProviderHook: ClassHook { + + static var targetName: String { + return EeveeSpotify.isOldSpotifyVersion + ? "Lyrics_CoreImpl.ScrollProvider" + : "Lyrics_NPVCommunicatorImpl.ScrollProvider" + } + + func isEnabledForTrack(_ track: SPTPlayerTrack) -> Bool { + return true } } @@ -25,9 +26,9 @@ class LyricsFullscreenViewControllerHook: ClassHook { orig.viewDidLoad() if UserDefaults.lyricsSource == .musixmatch - && lastLyricsError == nil - && !lastLyricsWasRomanized - && !lastLyricsAreEmpty { + && lastLyricsState.fallbackError == nil + && !lastLyricsState.wasRomanized + && !lastLyricsState.areEmpty { return } @@ -41,9 +42,7 @@ class LyricsFullscreenViewControllerHook: ClassHook { // -private var lastLyricsWasRomanized = false -private var lastLyricsAreEmpty = false -private var lastLyricsError: LyricsError? = nil +private var lastLyricsState = LyricsLoadingState() private var hasShownRestrictedPopUp = false private var hasShownUnauthorizedPopUp = false @@ -98,7 +97,7 @@ class LyricsOnlyViewControllerHook: ClassHook { // - if UserDefaults.fallbackReasons, let description = lastLyricsError?.description { + if UserDefaults.fallbackReasons, let description = lastLyricsState.fallbackError?.description { text.append( Dynamic.SPTEncoreAttributedString.alloc(interface: SPTEncoreAttributedString.self) .initWithString( @@ -109,7 +108,7 @@ class LyricsOnlyViewControllerHook: ClassHook { ) } - if lastLyricsWasRomanized { + if lastLyricsState.wasRomanized { text.append( Dynamic.SPTEncoreAttributedString.alloc(interface: SPTEncoreAttributedString.self) .initWithString( @@ -156,14 +155,14 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data { // + lastLyricsState = LyricsLoadingState() + do { lyricsDto = try repository.getLyrics(searchQuery, options: options) - lastLyricsError = nil } - catch let error { if let error = error as? LyricsError { - lastLyricsError = error + lastLyricsState.fallbackError = error switch error { @@ -198,7 +197,7 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data { } } else { - lastLyricsError = .UnknownError + lastLyricsState.fallbackError = .UnknownError } if source == .genius || !UserDefaults.geniusFallback { @@ -213,10 +212,11 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data { lyricsDto = try repository.getLyrics(searchQuery, options: options) } - lastLyricsWasRomanized = lyricsDto.romanization == .romanized - || (lyricsDto.romanization == .canBeRomanized && UserDefaults.lyricsOptions.romanization) - lastLyricsAreEmpty = lyricsDto.lines.isEmpty - + lastLyricsState.areEmpty = lyricsDto.lines.isEmpty + + lastLyricsState.wasRomanized = lyricsDto.romanization == .romanized + || (lyricsDto.romanization == .canBeRomanized && UserDefaults.lyricsOptions.romanization) + let lyrics = Lyrics.with { $0.colors = getLyricsColors() $0.data = lyricsDto.toLyricsData(source: source.description) diff --git a/Sources/EeveeSpotify/Lyrics/Models/LyricsLoadingState.swift b/Sources/EeveeSpotify/Lyrics/Models/LyricsLoadingState.swift new file mode 100644 index 0000000..1fa15b7 --- /dev/null +++ b/Sources/EeveeSpotify/Lyrics/Models/LyricsLoadingState.swift @@ -0,0 +1,7 @@ +import Foundation + +struct LyricsLoadingState { + var wasRomanized = false + var areEmpty = false + var fallbackError: LyricsError? = nil +}