Skip to content

Commit

Permalink
actual fix for #437 and Do Not Replace Lyrics option
Browse files Browse the repository at this point in the history
  • Loading branch information
whoeevee committed Oct 10, 2024
1 parent a579a07 commit e0fe39d
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 188 deletions.
9 changes: 6 additions & 3 deletions Sources/EeveeSpotify/DataLoaderServiceHooks.x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ class SPTDataLoaderServiceHook: ClassHook<NSObject>, SpotifySessionDelegate {

// orion:new
func shouldModify(_ url: URL) -> Bool {
let isModifyingCustomizeResponse = UserDefaults.patchType == .requests
return url.isLyrics || (url.isCustomize && isModifyingCustomizeResponse)
let isModifyingCustomizeResponse = PremiumPatchingGroup.isActive
let isModifyingLyrics = LyricsGroup.isActive

return (url.isLyrics && isModifyingLyrics)
|| (url.isCustomize && isModifyingCustomizeResponse)
}

func URLSession(
Expand Down Expand Up @@ -82,7 +85,7 @@ class SPTDataLoaderServiceHook: ClassHook<NSObject>, SpotifySessionDelegate {
return
}

if url.isLyrics, response.statusCode != 200 {
if shouldModify(url), url.isLyrics, response.statusCode != 200 {
let okResponse = HTTPURLResponse(
url: url,
statusCode: 200,
Expand Down
1 change: 0 additions & 1 deletion Sources/EeveeSpotify/Helpers/PopUpHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct PopUpHelper {

dialog.update(model)
dialog.setEventHandler({ state in

switch (state) {

case .primary: onPrimaryClick?()
Expand Down
27 changes: 27 additions & 0 deletions Sources/EeveeSpotify/Lyrics/CustomLyrics+AllTracksLyrics.x.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Orion

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

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

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

class LyricsScrollProviderHook: ClassHook<NSObject> {
typealias Group = LyricsGroup

static var targetName: String {
return EeveeSpotify.isOldSpotifyVersion
? "Lyrics_CoreImpl.ScrollProvider"
: "Lyrics_NPVCommunicatorImpl.ScrollProvider"
}

func isEnabledForTrack(_ track: SPTPlayerTrack) -> Bool {
return true
}
}
34 changes: 8 additions & 26 deletions Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
import Orion
import SwiftUI

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

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

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

class LyricsScrollProviderHook: ClassHook<NSObject> {

static var targetName: String {
return EeveeSpotify.isOldSpotifyVersion
? "Lyrics_CoreImpl.ScrollProvider"
: "Lyrics_NPVCommunicatorImpl.ScrollProvider"
}

func isEnabledForTrack(_ track: SPTPlayerTrack) -> Bool {
return true
}
}
//

class LyricsFullscreenViewControllerHook: ClassHook<UIViewController> {

typealias Group = LyricsGroup

static var targetName: String {
return EeveeSpotify.isOldSpotifyVersion
? "Lyrics_CoreImpl.FullscreenViewController"
Expand Down Expand Up @@ -62,6 +45,7 @@ private var hasShownUnauthorizedPopUp = false
//

class LyricsOnlyViewControllerHook: ClassHook<UIViewController> {
typealias Group = LyricsGroup

static var targetName: String {
return EeveeSpotify.isOldSpotifyVersion
Expand All @@ -70,7 +54,6 @@ class LyricsOnlyViewControllerHook: ClassHook<UIViewController> {
}

func viewDidLoad() {

orig.viewDidLoad()

guard
Expand Down Expand Up @@ -162,6 +145,7 @@ private func loadLyricsForCurrentTrack() throws {
case .lrclib: LrcLibLyricsRepository()
case .musixmatch: MusixmatchLyricsRepository.shared
case .petit: PetitLyricsRepository()
case .notReplaced: throw LyricsError.InvalidSource
}

let lyricsDto: LyricsDto
Expand All @@ -180,7 +164,6 @@ private func loadLyricsForCurrentTrack() throws {
switch error {

case .InvalidMusixmatchToken:

if !hasShownUnauthorizedPopUp {
PopUpHelper.showPopUp(
delayed: false,
Expand All @@ -192,7 +175,6 @@ private func loadLyricsForCurrentTrack() throws {
}

case .MusixmatchRestricted:

if !hasShownRestrictedPopUp {
PopUpHelper.showPopUp(
delayed: false,
Expand Down Expand Up @@ -226,7 +208,7 @@ private func loadLyricsForCurrentTrack() throws {
lastLyricsState.areEmpty = lyricsDto.lines.isEmpty

lastLyricsState.wasRomanized = lyricsDto.romanization == .romanized
|| (lyricsDto.romanization == .canBeRomanized && UserDefaults.lyricsOptions.romanization)
|| (lyricsDto.romanization == .canBeRomanized && UserDefaults.lyricsOptions.romanization)

lastLyricsState.loadedSuccessfully = true

Expand Down
2 changes: 2 additions & 0 deletions Sources/EeveeSpotify/Lyrics/Models/LyricsError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum LyricsError: Error, CustomStringConvertible {
case DecodingError
case NoSuchSong
case UnknownError
case InvalidSource

var description: String {
switch self {
Expand All @@ -16,6 +17,7 @@ enum LyricsError: Error, CustomStringConvertible {
case .DecodingError: "decoding_error".localized
case .NoCurrentTrack: "no_current_track".localized
case .UnknownError: "unknown_error".localized
case .InvalidSource: ""
}
}
}
14 changes: 14 additions & 0 deletions Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ enum LyricsSource: Int, CaseIterable, CustomStringConvertible {
case lrclib
case musixmatch
case petit
case notReplaced

static var allCases: [LyricsSource] {
return [.genius, .lrclib, .musixmatch, .petit]
}

var description: String {
switch self {
case .genius: "Genius"
case .lrclib: "LRCLIB"
case .musixmatch: "Musixmatch"
case .petit: "PetitLyrics"
case .notReplaced: "Spotify"
}
}

var isReplacing: Bool { self != .notReplaced }

static var defaultSource: LyricsSource {
Locale.isInRegion("JP", orHasLanguage: "ja")
? .petit
: .lrclib
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation

extension UserDefaults {

private static let defaults = UserDefaults.standard

private static let lyricsSourceKey = "lyricsSource"
Expand All @@ -21,11 +20,7 @@ extension UserDefaults {
return LyricsSource(rawValue: rawValue)!
}

if Locale.isInRegion("JP", orHasLanguage: "ja") {
return .petit
}

return .lrclib
return LyricsSource.defaultSource
}
set (newSource) {
defaults.set(newSource.rawValue, forKey: lyricsSourceKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SpotifySessionDelegateBootstrapHook: ClassHook<NSObject>, SpotifySessionDe
}
else {
UserDefaults.patchType = .requests
PremiumPatching().activate()
PremiumPatchingGroup().activate()
}

NSLog("[EeveeSpotify] Fetched bootstrap, \(UserDefaults.patchType) was set")
Expand Down
2 changes: 1 addition & 1 deletion Sources/EeveeSpotify/Premium/LikedSongsEnabler.x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ private let likedTracksRow: [String: Any] = [
]

class HUBViewModelBuilderImplementationHook: ClassHook<NSObject> {
typealias Group = PremiumPatching
typealias Group = PremiumPatchingGroup
static let targetName: String = "HUBViewModelBuilderImplementation"

func addJSONDictionary(_ dictionary: NSDictionary?) {
Expand Down
50 changes: 27 additions & 23 deletions Sources/EeveeSpotify/Premium/ServerSidedReminder.x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Orion
import UIKit

class StreamQualitySettingsSectionHook: ClassHook<NSObject> {
typealias Group = PremiumPatching
typealias Group = PremiumPatchingGroup
static let targetName = "StreamQualitySettingsSection"

func shouldResetSelection() -> Bool {
Expand All @@ -15,17 +15,8 @@ class StreamQualitySettingsSectionHook: ClassHook<NSObject> {
}
}

//

private func showOfflineModePopUp() {
PopUpHelper.showPopUp(
message: "playlist_downloading_popup".localized,
buttonText: "OK".uiKitLocalized
)
}

class ContentOffliningUIHelperImplementationHook: ClassHook<NSObject> {
typealias Group = PremiumPatching
typealias Group = PremiumPatchingGroup
static let targetName = "Offline_ContentOffliningUIImpl.ContentOffliningUIHelperImplementation"

func downloadToggledWithCurrentAvailability(
Expand All @@ -34,18 +25,31 @@ class ContentOffliningUIHelperImplementationHook: ClassHook<NSObject> {
removeAction: NSObject,
pageIdentifier: String,
pageURI: URL
) -> String {
if pageIdentifier == "spotify:local-files" {
return orig.downloadToggledWithCurrentAvailability(
availability,
addAction: addAction,
removeAction: removeAction,
pageIdentifier: pageIdentifier,
pageURI: pageURI
)
}
) -> String? {
let isPlaylist = [
"free-tier-playlist",
"playlist/ondemand"
].contains(pageIdentifier)

PopUpHelper.showPopUp(
message: "playlist_downloading_popup".localized,
buttonText: "OK".uiKitLocalized,
secondButtonText: isPlaylist
? "download_local_playlist".localized
: nil,
onSecondaryClick: isPlaylist
? {
_ = self.orig.downloadToggledWithCurrentAvailability(
availability,
addAction: addAction,
removeAction: removeAction,
pageIdentifier: pageIdentifier,
pageURI: pageURI
)
}
: nil
)

showOfflineModePopUp()
return pageIdentifier
return nil
}
}
2 changes: 1 addition & 1 deletion Sources/EeveeSpotify/Premium/TrackRowsEnabler.x.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Orion

class SPTFreeTierArtistHubRemoteURLResolverHook: ClassHook<NSObject> {
typealias Group = PremiumPatching
typealias Group = PremiumPatchingGroup
static let targetName = "SPTFreeTierArtistHubRemoteURLResolver"

func initWithViewURI(
Expand Down
5 changes: 2 additions & 3 deletions Sources/EeveeSpotify/Settings/Views/EeveeSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import UIKit

struct EeveeSettingsView: View {
let navigationController: UINavigationController
static let spotifyAccentColor = Color(hex: "#1ed760")

@State private var hasShownCommonIssuesTip = UserDefaults.hasShownCommonIssuesTip
@State private var isClearingData = false
Expand All @@ -18,9 +19,7 @@ struct EeveeSettingsView: View {

init(navigationController: UINavigationController) {
self.navigationController = navigationController

let spotifyAccentColor = UIColor(Color(hex: "#1ed760"))
UIView.appearance().tintColor = spotifyAccentColor
UIView.appearance().tintColor = UIColor(EeveeSettingsView.spotifyAccentColor)
}

var body: some View {
Expand Down
Loading

0 comments on commit e0fe39d

Please sign in to comment.