diff --git a/Sources/EeveeSpotify/Lyrics/CustomLyrics+HideOnError.x.swift b/Sources/EeveeSpotify/Lyrics/CustomLyrics+HideOnError.x.swift new file mode 100644 index 0000000..dc6a9c3 --- /dev/null +++ b/Sources/EeveeSpotify/Lyrics/CustomLyrics+HideOnError.x.swift @@ -0,0 +1,30 @@ +import Orion +import UIKit + +class fefewfwfwefewefw: ClassHook { + typealias Group = LyricsGroup + + static var targetName: String { + switch EeveeSpotify.hookTarget { + case .lastAvailableiOS14: return "Lyrics_CoreImpl.ErrorViewController" + default: return "Lyrics_NPVCommunicatorImpl.ErrorViewController" + } + } + + func loadView() { + orig.loadView() + + guard UserDefaults.lyricsOptions.hideOnError, let controller = nowPlayingScrollViewController else { + return + } + + var providers = controller.activeProviders + + providers.removeAll( + where: { NSStringFromClass(type(of: $0)) == HookTargetNameHelper.lyricsScrollProvider } + ) + + controller.activeProviders = providers + controller.collectionView().reloadData() + } +} diff --git a/Sources/EeveeSpotify/Lyrics/Models/Extensions/NowPlayingScrollViewController+Extension.swift b/Sources/EeveeSpotify/Lyrics/Models/Extensions/NowPlayingScrollViewController+Extension.swift index 1c24718..db11af8 100644 --- a/Sources/EeveeSpotify/Lyrics/Models/Extensions/NowPlayingScrollViewController+Extension.swift +++ b/Sources/EeveeSpotify/Lyrics/Models/Extensions/NowPlayingScrollViewController+Extension.swift @@ -24,6 +24,23 @@ extension NowPlayingScrollViewController { // + private var dataSource: NSObject { + get { + Ivars(nowPlayingScrollViewModel).dataSource + } + } + + var activeProviders: Array { + get { + Ivars>(dataSource).activeProviders + } + set { + Ivars>(dataSource).activeProviders = newValue + } + } + + // + var backgroundViewController: SPTNowPlayingBackgroundViewController { get { Ivars(self).backgroundViewController diff --git a/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions+UserDefaults.swift b/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions+UserDefaults.swift index a81f058..5c0fec8 100644 --- a/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions+UserDefaults.swift +++ b/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions+UserDefaults.swift @@ -8,7 +8,8 @@ extension UserDefaults { musixmatchLanguage: Locale.current.languageCode ?? "", lrclibUrl: LrclibLyricsRepository.originalApiUrl, geniusFallback: true, - showFallbackReasons: true + showFallbackReasons: true, + hideOnError: false ) ) static var lyricsOptions diff --git a/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions.swift b/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions.swift index 73bc645..4fef1d3 100644 --- a/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions.swift +++ b/Sources/EeveeSpotify/Lyrics/Models/Settings/LyricsOptions.swift @@ -6,4 +6,5 @@ struct LyricsOptions: Codable, Hashable { var lrclibUrl: String var geniusFallback: Bool var showFallbackReasons: Bool + var hideOnError: Bool } diff --git a/Sources/EeveeSpotify/Settings/Sections/Lyrics/Views/EeveeLyricsSettingsView.swift b/Sources/EeveeSpotify/Settings/Sections/Lyrics/Views/EeveeLyricsSettingsView.swift index a0203a7..6165b0f 100644 --- a/Sources/EeveeSpotify/Settings/Sections/Lyrics/Views/EeveeLyricsSettingsView.swift +++ b/Sources/EeveeSpotify/Settings/Sections/Lyrics/Views/EeveeLyricsSettingsView.swift @@ -12,6 +12,7 @@ struct EeveeLyricsSettingsView: View { geniusFallbackSection() } + hideOnErrorSection() romanizedLyricsSection() if viewModel.lyricsSource == .musixmatch { @@ -59,6 +60,17 @@ struct EeveeLyricsSettingsView: View { } } + @ViewBuilder private func hideOnErrorSection() -> some View { + Section { + Toggle( + "hide_lyrics_on_error".localized, + isOn: $viewModel.lyricsOptions.hideOnError + ) + } footer: { + Text("hide_lyrics_on_error_description".localized) + } + } + @ViewBuilder private func musixmatchLanguageSection() -> some View { Section { HStack { diff --git a/layout/Library/Application Support/EeveeSpotify.bundle/en.lproj/Localizable.strings b/layout/Library/Application Support/EeveeSpotify.bundle/en.lproj/Localizable.strings index 6107e99..210c531 100644 --- a/layout/Library/Application Support/EeveeSpotify.bundle/en.lproj/Localizable.strings +++ b/layout/Library/Application Support/EeveeSpotify.bundle/en.lproj/Localizable.strings @@ -55,6 +55,9 @@ genius_fallback_description = "Load lyrics from Genius if there is a problem wit show_fallback_reasons = "Show Fallback Reasons"; +hide_lyrics_on_error = "Hide on Error"; +hide_lyrics_on_error_description = "Remove the lyrics component if lyrics fail to load."; + romanized_lyrics = "Romanized Lyrics"; romanized_lyrics_description = "Display romanized lyrics for Japanese, Korean, and Chinese."; diff --git a/layout/Library/Application Support/EeveeSpotify.bundle/ru.lproj/Localizable.strings b/layout/Library/Application Support/EeveeSpotify.bundle/ru.lproj/Localizable.strings index d3d2e74..d0edfbe 100644 --- a/layout/Library/Application Support/EeveeSpotify.bundle/ru.lproj/Localizable.strings +++ b/layout/Library/Application Support/EeveeSpotify.bundle/ru.lproj/Localizable.strings @@ -54,6 +54,9 @@ genius_fallback_description = "Загружать тексты из Genius пр show_fallback_reasons = "Показывать проблемы"; +hide_lyrics_on_error = "Скрывать при ошибке"; +hide_lyrics_on_error_description = "Скрывать компонент текста, если не удается загрузить текст."; + romanized_lyrics = "Латинизация текстов"; romanized_lyrics_description = "Отображать латинизированный текст для японского, корейского и китайского языков.";