From e153fff66e4bd0b5ce5d06cd6d842a64b1a4f2cb Mon Sep 17 00:00:00 2001 From: eevee Date: Sun, 30 Jun 2024 09:34:53 +0300 Subject: [PATCH] ios 14 --- Sources/EeveeSpotify/DarkPopUps.x.swift | 10 +++- .../EeveeSpotify/Lyrics/CustomLyrics.x.swift | 48 ++++++++++++++----- .../Headers/SPTEncoreAttributedString.swift | 8 +++- .../Models/Headers/SPTEncoreLabel.swift | 1 + .../Models/Headers/SPTEncoreTypeStyle.swift | 5 ++ 5 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 Sources/EeveeSpotify/Models/Headers/SPTEncoreTypeStyle.swift diff --git a/Sources/EeveeSpotify/DarkPopUps.x.swift b/Sources/EeveeSpotify/DarkPopUps.x.swift index bc65696..ac52dd8 100644 --- a/Sources/EeveeSpotify/DarkPopUps.x.swift +++ b/Sources/EeveeSpotify/DarkPopUps.x.swift @@ -16,8 +16,16 @@ class EncoreLabelHook: ClassHook { ) ~= "SPTEncorePopUpContainer" { let label = Dynamic.convert(target.subviews.first!, to: UILabel.self) + + let superview: UIView? + + if #available(iOS 15.0, *) { + superview = target.superview?.superview?.superview?.superview + } else { + superview = target.superview?.superview?.superview + } - if !(String(describing: target.superview?.superview?.superview?.superview) ~= "Primary") { + if !(String(describing: superview) ~= "Primary") { label.textColor = .white } } diff --git a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift index 38b3f47..a00dcfb 100644 --- a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift +++ b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift @@ -38,8 +38,14 @@ private var hasShownUnauthorizedPopUp = false // class LyricsOnlyViewControllerHook: ClassHook { - - static let targetName = "Lyrics_NPVCommunicatorImpl.LyricsOnlyViewController" + + static var targetName: String { + if #available(iOS 15.0, *) { + "Lyrics_NPVCommunicatorImpl.LyricsOnlyViewController" + } else { + "Lyrics_CoreImpl.LyricsOnlyViewController" + } + } func viewDidLoad() { @@ -50,20 +56,32 @@ class LyricsOnlyViewControllerHook: ClassHook { } guard - let lyricsHeaderViewController = target.parent?.children.first, - let lyricsLabel = lyricsHeaderViewController.view.subviews.first + let lyricsHeaderViewController = target.parent?.children.first else { return } + // + + let lyricsLabel: UIView? + + if #available(iOS 15.0, *) { + lyricsLabel = lyricsHeaderViewController.view.subviews.first + } else { + lyricsLabel = lyricsHeaderViewController.view.subviews.first?.subviews.first + } + + guard let lyricsLabel = lyricsLabel else { + return + } + + // + let encoreLabel = Dynamic.convert(lyricsLabel, to: SPTEncoreLabel.self) - let attributedString = Dynamic.convert( - encoreLabel.text().firstObject as AnyObject, - to: SPTEncoreAttributedString.self - ) - - var text = [attributedString] + var text = [ + encoreLabel.text().firstObject + ] if let description = lastLyricsError?.description { @@ -73,14 +91,22 @@ class LyricsOnlyViewControllerHook: ClassHook { attributes.setForegroundColor(.white.withAlphaComponent(0.5)) }) + let typeStyle = type( + of: Dynamic.SPTEncoreTypeStyle.alloc(interface: SPTEncoreTypeStyle.self) + ).bodyMediumBold() + text.append( Dynamic.SPTEncoreAttributedString.alloc(interface: SPTEncoreAttributedString.self) .initWithString( "\nFallback: \(description)", - typeStyle: attributedString.typeStyle(), + typeStyle: typeStyle, attributes: attributes ) ) + + if #unavailable(iOS 15.0) { + encoreLabel.setNumberOfLines(2) + } } encoreLabel.setText(text as NSArray) diff --git a/Sources/EeveeSpotify/Models/Headers/SPTEncoreAttributedString.swift b/Sources/EeveeSpotify/Models/Headers/SPTEncoreAttributedString.swift index c4fb466..15eeda2 100644 --- a/Sources/EeveeSpotify/Models/Headers/SPTEncoreAttributedString.swift +++ b/Sources/EeveeSpotify/Models/Headers/SPTEncoreAttributedString.swift @@ -1,8 +1,12 @@ import Foundation @objc protocol SPTEncoreAttributedString { - func initWithString(_ string: String, typeStyle: Any, attributes: Any) -> SPTEncoreAttributedString + func initWithString(_ string: String, typeStyle: SPTEncoreTypeStyle, attributes: SPTEncoreAttributes) -> SPTEncoreAttributedString func text() -> String - func typeStyle() -> Any + + @available(iOS 15.0, *) + func typeStyle() -> SPTEncoreTypeStyle + + @available(iOS 15.0, *) func attributes() -> SPTEncoreAttributes } diff --git a/Sources/EeveeSpotify/Models/Headers/SPTEncoreLabel.swift b/Sources/EeveeSpotify/Models/Headers/SPTEncoreLabel.swift index 81e0939..f29eddf 100644 --- a/Sources/EeveeSpotify/Models/Headers/SPTEncoreLabel.swift +++ b/Sources/EeveeSpotify/Models/Headers/SPTEncoreLabel.swift @@ -2,5 +2,6 @@ import Foundation @objc protocol SPTEncoreLabel { func text() -> NSArray + func setNumberOfLines(_ number: Int) func setText(_ text: NSArray) } diff --git a/Sources/EeveeSpotify/Models/Headers/SPTEncoreTypeStyle.swift b/Sources/EeveeSpotify/Models/Headers/SPTEncoreTypeStyle.swift new file mode 100644 index 0000000..560774d --- /dev/null +++ b/Sources/EeveeSpotify/Models/Headers/SPTEncoreTypeStyle.swift @@ -0,0 +1,5 @@ +import Foundation + +@objc protocol SPTEncoreTypeStyle { + static func bodyMediumBold() -> SPTEncoreTypeStyle +}