From 398a11970a1c519c0ed3846526d7034aaad478a1 Mon Sep 17 00:00:00 2001 From: eevee Date: Sun, 16 Jun 2024 18:07:20 +0300 Subject: [PATCH] ipad stuff and version section --- .../EeveeSpotify/Lyrics/CustomLyrics.x.swift | 2 +- .../MusixmatchLyricsDataSource.swift | 5 +- .../Extensions/UIDevice+Extension.swift | 7 +++ .../Settings/Models/GitHubReleaseInfo.swift | 5 ++ .../ListRowSeparatorHidden.swift | 13 +++++ ...eveeSettingsView+LyricsColorsSection.swift | 1 - .../EeveeSettingsView+VersionSection.swift | 48 +++++++++++++++++++ .../Settings/Views/EeveeSettingsView.swift | 20 ++++++-- ...ettingsViewController+LyricsSections.swift | 2 +- 9 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 Sources/EeveeSpotify/Models/Extensions/UIDevice+Extension.swift create mode 100644 Sources/EeveeSpotify/Settings/Models/GitHubReleaseInfo.swift create mode 100644 Sources/EeveeSpotify/Settings/ViewModifiers/ListRowSeparatorHidden.swift create mode 100644 Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+VersionSection.swift diff --git a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift index ac77481..d374333 100644 --- a/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift +++ b/Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift @@ -55,7 +55,7 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data { PopUpHelper.showPopUp( delayed: false, - message: "The tweak is unable to load lyrics from Musixmatch due to Unauthorized error. Please check or update your Musixmatch token.", + message: "The tweak is unable to load lyrics from Musixmatch due to Unauthorized error. Please check or update your Musixmatch token. If you use an iPad, you should get the token from the Musixmatch app for iPad.", buttonText: "OK" ) break diff --git a/Sources/EeveeSpotify/Lyrics/DataSources/MusixmatchLyricsDataSource.swift b/Sources/EeveeSpotify/Lyrics/DataSources/MusixmatchLyricsDataSource.swift index c20c78a..ac7d0f9 100644 --- a/Sources/EeveeSpotify/Lyrics/DataSources/MusixmatchLyricsDataSource.swift +++ b/Sources/EeveeSpotify/Lyrics/DataSources/MusixmatchLyricsDataSource.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit struct MusixmatchLyricsDataSource { @@ -14,7 +15,9 @@ struct MusixmatchLyricsDataSource { var finalQuery = query finalQuery["usertoken"] = UserDefaults.musixmatchToken - finalQuery["app_id"] = "mac-ios-v2.0" + finalQuery["app_id"] = UIDevice.current.isIpad + ? "mac-ios-ipad-v1.0" + : "mac-ios-v2.0" let queryString = finalQuery.queryString.addingPercentEncoding( withAllowedCharacters: .urlHostAllowed diff --git a/Sources/EeveeSpotify/Models/Extensions/UIDevice+Extension.swift b/Sources/EeveeSpotify/Models/Extensions/UIDevice+Extension.swift new file mode 100644 index 0000000..90dc552 --- /dev/null +++ b/Sources/EeveeSpotify/Models/Extensions/UIDevice+Extension.swift @@ -0,0 +1,7 @@ +import UIKit + +extension UIDevice { + var isIpad: Bool { + self.userInterfaceIdiom == .pad + } +} diff --git a/Sources/EeveeSpotify/Settings/Models/GitHubReleaseInfo.swift b/Sources/EeveeSpotify/Settings/Models/GitHubReleaseInfo.swift new file mode 100644 index 0000000..91c6d52 --- /dev/null +++ b/Sources/EeveeSpotify/Settings/Models/GitHubReleaseInfo.swift @@ -0,0 +1,5 @@ +import Foundation + +struct GitHubReleaseInfo: Decodable { + var tag_name: String +} diff --git a/Sources/EeveeSpotify/Settings/ViewModifiers/ListRowSeparatorHidden.swift b/Sources/EeveeSpotify/Settings/ViewModifiers/ListRowSeparatorHidden.swift new file mode 100644 index 0000000..7c5f436 --- /dev/null +++ b/Sources/EeveeSpotify/Settings/ViewModifiers/ListRowSeparatorHidden.swift @@ -0,0 +1,13 @@ +import SwiftUI + +struct ListRowSeparatorHidden: ViewModifier { + func body(content: Content) -> some View { + if #available(iOS 15.0, *) { + content + .listRowSeparator(.hidden) + } + else { + content + } + } +} diff --git a/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+LyricsColorsSection.swift b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+LyricsColorsSection.swift index 561d796..e0adace 100644 --- a/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+LyricsColorsSection.swift +++ b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+LyricsColorsSection.swift @@ -28,7 +28,6 @@ You can set a static color or a normalization factor based on the extracted trac get: { Color(hex: lyricsColors.staticColor) }, set: { lyricsColors.staticColor = $0.hexString } ), - supportsOpacity: false ) } diff --git a/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+VersionSection.swift b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+VersionSection.swift new file mode 100644 index 0000000..9546876 --- /dev/null +++ b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView+VersionSection.swift @@ -0,0 +1,48 @@ +import SwiftUI + +extension EeveeSettingsView { + + func loadVersion() async throws { + + let (data, _) = try await URLSession.shared.data( + from: URL(string: "https://api.github.com/repos/whoeevee/EeveeSpotify/releases/latest")! + ) + + let tag = try JSONDecoder().decode(GitHubReleaseInfo.self, from: data).tag_name + latestVersion = String(tag.dropFirst(5)) + } + + private var isUpdateAvailable: Bool { + guard + let latest = Double(latestVersion), + let current = Double(EeveeSpotify.version) + else { + return false + } + + return latest > current + } + + @ViewBuilder func VersionSection() -> some View { + + Section { + if isUpdateAvailable { + Link( + "Update Available", + destination: URL(string: "https://github.com/whoeevee/EeveeSpotify/releases")! + ) + } + } footer: { + VStack(alignment: .leading) { + Text("v\(EeveeSpotify.version)") + + if latestVersion.isEmpty { + HStack(spacing: 10) { + ProgressView() + Text("Checking for Update...") + } + } + } + } + } +} diff --git a/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView.swift b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView.swift index e1dc140..777294a 100644 --- a/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView.swift +++ b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsView.swift @@ -5,13 +5,17 @@ struct EeveeSettingsView: View { @State var musixmatchToken = UserDefaults.musixmatchToken @State var patchType = UserDefaults.patchType - @State var lyricsSource = UserDefaults.lyricsSource @State var overwriteConfiguration = UserDefaults.overwriteConfiguration + + @State var lyricsSource = UserDefaults.lyricsSource @State var lyricsColors = UserDefaults.lyricsColors + + @State var latestVersion = "" var body: some View { List { + VersionSection() PremiumSections() @@ -37,16 +41,22 @@ struct EeveeSettingsView: View { Text("Reset Data") } } + + if !UIDevice.current.isIpad { + Spacer() + .frame(height: 40) + .listRowBackground(Color.clear) + .modifier(ListRowSeparatorHidden()) + } } .listStyle(GroupedListStyle()) - - .padding(.bottom, 60) .ignoresSafeArea(.keyboard) .animation(.default, value: lyricsSource) .animation(.default, value: patchType) .animation(.default, value: lyricsColors) + .animation(.default, value: latestVersion) .onAppear { UIView.appearance( @@ -54,6 +64,10 @@ struct EeveeSettingsView: View { ).tintColor = UIColor(Color(hex: "#1ed760")) WindowHelper.shared.overrideUserInterfaceStyle(.dark) + + Task { + try await loadVersion() + } } } } diff --git a/Sources/EeveeSpotify/Settings/Views/EeveeSettingsViewController+LyricsSections.swift b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsViewController+LyricsSections.swift index e4e426a..46e38a9 100644 --- a/Sources/EeveeSpotify/Settings/Views/EeveeSettingsViewController+LyricsSections.swift +++ b/Sources/EeveeSpotify/Settings/Views/EeveeSettingsViewController+LyricsSections.swift @@ -58,7 +58,7 @@ LRCLIB: The most open service, offering time-synced lyrics. However, it lacks ly Musixmatch: The service Spotify uses. Provides time-synced lyrics for many songs, but you'll need a user token to use this source. -If the tweak is unable to find a song or process the lyrics, you'll see a "Couldn't load the lyrics for this song" message. The lyrics might be wrong for some songs (e.g. another song, song article) when using Genius due to how the tweak searches songs. I've made it work in most cases. +If the tweak is unable to find a song or process the lyrics, you'll see a "Couldn't load the lyrics for this song" message. The lyrics might be wrong for some songs when using Genius due to how the tweak searches songs. I've made it work in most cases. """)) { Picker( "Lyrics Source",