Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Features/Welcome/WelcomeView.swift3// Description: Welcome and sign-in screen; mini player.4import SwiftUI5import SPMusicCore67/// First launch, or after signing out: who you are. Two ways in — a passkey, or approving this Mac from a browser8/// that is already signed in.9struct WelcomeView: View {10 @Environment(AppModel.self) private var model11 @State private var linkTask: Task<Void, Never>?1213 var body: some View {14 ZStack {15 LinearGradient(colors: [Color.accentColor.opacity(0.22), .clear], startPoint: .top, endPoint: .center).ignoresSafeArea()16 VStack(spacing: 22) {17 Image(nsImage: NSApp.applicationIconImage).resizable().frame(width: 112, height: 112).shadow(color: .black.opacity(0.25), radius: 14, y: 8)18 VStack(spacing: 6) {19 Text("SP Music").font(.system(size: 34, weight: .bold))20 Text("Votre musique, depuis votre cluster — et sur ce Mac, même sans Internet.").font(.title3).foregroundStyle(.secondary).multilineTextAlignment(.center)21 }22 if let link = model.deviceLink {23 VStack(spacing: 12) {24 Text("Approuvez ce Mac dans votre navigateur").font(.headline)25 Text(link.userCode).font(.system(size: 38, weight: .bold, design: .monospaced)).tracking(4).textSelection(.enabled)26 .padding(.horizontal, 22).padding(.vertical, 10).background(.quaternary, in: RoundedRectangle(cornerRadius: 12))27 Text("Une page s’est ouverte sur \(model.settings.serverURL.host ?? "le serveur"). Connectez-vous avec votre clé d’accès, vérifiez que le code est le même, puis autorisez.")28 .font(.callout).foregroundStyle(.secondary).multilineTextAlignment(.center).frame(maxWidth: 420)29 HStack {30 ProgressView().controlSize(.small)31 Text("En attente de votre approbation…").font(.callout).foregroundStyle(.secondary)32 }33 HStack {34 Button("Rouvrir la page") { if let u = URL(string: link.verificationUrl) { NSWorkspace.shared.open(u) } }35 Button("Annuler") { linkTask?.cancel(); model.deviceLink = nil }36 }37 }38 .padding(22).background(.regularMaterial, in: RoundedRectangle(cornerRadius: 16))39 } else {40 VStack(spacing: 10) {41 Button { Task { await model.signInWithPasskey() } } label: {42 Label("Se connecter avec une clé d’accès", systemImage: "person.badge.key.fill").frame(width: 300).padding(.vertical, 4)43 }44 .buttonStyle(.borderedProminent).controlSize(.large).keyboardShortcut(.defaultAction)45 Button { linkTask = Task { await model.beginDeviceLink() } } label: {46 Label("Associer avec le navigateur", systemImage: "safari").frame(width: 300).padding(.vertical, 4)47 }48 .controlSize(.large)49 if model.signingIn { ProgressView().controlSize(.small).padding(.top, 4) }50 }51 .disabled(model.signingIn)52 }53 if let e = model.signInError {54 Label(e, systemImage: "exclamationmark.triangle.fill").font(.callout).foregroundStyle(.orange).multilineTextAlignment(.center).frame(maxWidth: 460)55 }56 Text("Lecteur privé : aucun compte n’est créé ici. Touch ID et votre empreinte restent sur votre Mac ; le serveur ne reçoit qu’une signature.\nServeur : \(model.settings.serverURL.absoluteString)")57 .font(.caption).foregroundStyle(.tertiary).multilineTextAlignment(.center).frame(maxWidth: 460).padding(.top, 6)58 }59 .padding(40)60 }61 .frame(maxWidth: .infinity, maxHeight: .infinity)62 }63}6465/// A small always-available player.66struct MiniPlayerView: View {67 @Environment(AppModel.self) private var model68 var body: some View {69 let p = model.playback70 VStack(spacing: 10) {71 ArtworkView(artworkID: p.currentTrack?.artworkID, size: 220, cornerRadius: 10, externalKey: p.currentTrack?.externalFileURL != nil ? p.currentTrack?.id : nil)72 .shadow(color: .black.opacity(0.25), radius: 10, y: 5)73 VStack(spacing: 2) {74 Text(p.currentTrack?.title ?? "Aucun titre").font(.headline).lineLimit(1)75 Text(p.currentTrack?.artistName ?? " ").font(.subheadline).foregroundStyle(.secondary).lineLimit(1)76 }77 HStack(spacing: 6) {78 Text(Format.duration(seconds: p.position)).font(.caption2.monospacedDigit()).foregroundStyle(.secondary)79 SeekBar()80 Text(Format.duration(seconds: p.duration)).font(.caption2.monospacedDigit()).foregroundStyle(.secondary)81 }82 TransportButtons()83 VolumeSlider(width: 140)84 }85 .padding(18).frame(width: 260)86 .background(.regularMaterial)87 }88}89