Skip to content

Commit

Permalink
ipad stuff and version section
Browse files Browse the repository at this point in the history
  • Loading branch information
whoeevee committed Jun 16, 2024
1 parent a2388ed commit 398a119
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import UIKit

struct MusixmatchLyricsDataSource {

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import UIKit

extension UIDevice {
var isIpad: Bool {
self.userInterfaceIdiom == .pad
}
}
5 changes: 5 additions & 0 deletions Sources/EeveeSpotify/Settings/Models/GitHubReleaseInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

struct GitHubReleaseInfo: Decodable {
var tag_name: String
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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...")
}
}
}
}
}
}
20 changes: 17 additions & 3 deletions Sources/EeveeSpotify/Settings/Views/EeveeSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -37,23 +41,33 @@ 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(
whenContainedInInstancesOf: [UIAlertController.self]
).tintColor = UIColor(Color(hex: "#1ed760"))

WindowHelper.shared.overrideUserInterfaceStyle(.dark)

Task {
try await loadVersion()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 398a119

Please sign in to comment.