Yandex Music client for Apple TV

tvOS 17+ SwiftUI client for the unofficial Yandex Music API: rotor stations
with feedback, library, search, artist and album pages, synced lyrics, and
system Now Playing integration.
This commit is contained in:
2026-09-17 20:38:19 +03:00
commit acd50280bc
70 changed files with 4588 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
import Foundation
import SwiftUI
@MainActor
final class AppState: ObservableObject {
@Published var token: String?
@Published var accountName: String = ""
@Published var isBooting = true
var isAuthorized: Bool { token != nil }
init() {
token = Keychain.get("token")
}
func boot() async {
isBooting = true
defer { isBooting = false }
guard let token else { return }
await YMClient.shared.setToken(token)
do {
let status = try await YMClient.shared.accountStatus()
accountName = status.account.displayName
?? status.account.fullName
?? status.account.login
?? "Аккаунт"
await PlayerController.shared.refreshLikes()
} catch {
log.error("boot: \(error.localizedDescription)")
// A dead token should not trap the user on a broken screen.
if case let YMError.http(status, _) = error, status == 401 || status == 403 {
signOut()
}
}
}
func signIn(with token: String) async {
let trimmed = token.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return }
Keychain.set(trimmed, for: "token")
self.token = trimmed
await boot()
}
func signOut() {
Keychain.set(nil, for: "token")
token = nil
accountName = ""
Task { await YMClient.shared.setToken(nil) }
}
}
+41
View File
@@ -0,0 +1,41 @@
import SwiftUI
@main
struct YaMusekApp: App {
@StateObject private var state = AppState()
@StateObject private var player = PlayerController.shared
var body: some Scene {
WindowGroup {
Group {
// The API client only learns the token inside boot(), so nothing
// that makes requests may appear before it finishes.
if state.isBooting {
SplashView()
} else if state.isAuthorized {
RootView()
} else {
LoginView()
}
}
.environmentObject(state)
.environmentObject(player)
.preferredColorScheme(.dark)
.task { await state.boot() }
}
}
}
struct SplashView: View {
var body: some View {
ZStack {
Color.black.ignoresSafeArea()
VStack(spacing: 24) {
Text("YaMusek")
.font(.system(size: 72, weight: .heavy, design: .rounded))
.foregroundStyle(Color.ymAccent)
ProgressView()
}
}
}
}