Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Music9// File : Features/Settings/SettingsView.swift10// Description : Settings: account entry, cellular data, audio quality,11// synchronisation.12// Module : Features13// Repository : https://git.spboucher.ai/sp-music-ios14// Created : 2026-11-1715// Last Modified : 2026-11-1716//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author : Simon-Pierre Boucher22// Position : Professor of Finance23// Institution : Université du Québec en Outaouais (UQO)24// Department : Département des sciences administratives25// Organization : SP Boucher26//27// Website : https://spboucher.ai28// Git : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General : info@spboucher.ai35// Professional : contact@spboucher.ai36// Direct : simon@spboucher.ai37// Research : research@spboucher.ai38// Development : dev@spboucher.ai39// Support : support@spboucher.ai40// Security/Admin : admin@spboucher.ai41// Notifications : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification : Public68// Distribution : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License : None specified (no license file in this repository)82// Maintainer : Simon-Pierre Boucher83// Technical Contact: dev@spboucher.ai84//85// =============================================================================86// END OF SP BOUCHER SOURCE HEADER87// =============================================================================8889import SPMusicCore90import SwiftUI9192struct SettingsView: View {93 @Environment(AppEnvironment.self) private var env94 var body: some View {95 List {96 Section {97 NavigationLink(value: Route.account) {98 HStack(spacing: 12) {99 Image(systemName: "person.crop.circle.fill").font(.system(size: 38)).foregroundStyle(.spBrand)100 VStack(alignment: .leading, spacing: 2) {101 Text(env.auth.me?.displayName ?? "Non connecté").font(.headline)102 Text(env.auth.state == .signedIn ? (env.auth.unverified ? "Session non vérifiée (hors ligne)" : env.auth.me?.email ?? "") : "Connexion requise pour la diffusion").font(.footnote).foregroundStyle(Color.spMuted)103 }104 }105 }106 .accessibilityIdentifier("settings-account")107 }108 Section("Lecture et réseau") {109 NavigationLink(value: Route.networkSettings) { Label("Données cellulaires et téléchargements", systemImage: "antenna.radiowaves.left.and.right") }110 NavigationLink(value: Route.audioSettings) { Label("Qualité audio", systemImage: "waveform") }111 NavigationLink(value: Route.storage) { Label("Stockage", systemImage: "internaldrive") }112 }113 Section {114 Toggle(isOn: Binding(get: { env.settings.biometricLock }, set: { on in Task { await env.setBiometricLock(on) } })) {115 Label("Verrouiller avec \(BiometricLock.kindName)", systemImage: "faceid")116 }117 .tint(Color.spEmber).disabled(!BiometricLock.isAvailable)118 } header: { Text("Confidentialité") } footer: {119 Text("Demandé à l'ouverture de l'app. La lecture en cours et les commandes de l'écran verrouillé continuent de fonctionner.")120 }121 Section {122 HStack { Text("Dernière synchronisation"); Spacer(); Text(env.lastSync.map { $0.formatted(.relative(presentation: .named)) } ?? "jamais").foregroundStyle(Color.spMuted) }123 Button { Task { await env.syncNow() } } label: {124 HStack { Text("Synchroniser maintenant"); Spacer(); if env.syncState == .running { ProgressView() } }125 }126 .disabled(env.auth.state != .signedIn || !env.isOnline || env.syncState == .running)127 Button("Relire toute la bibliothèque") { Task { await env.syncNow(full: true) } }.disabled(env.auth.state != .signedIn || !env.isOnline || env.syncState == .running)128 } header: { Text("Synchronisation avec MacLustr") } footer: {129 if case .failed(let why) = env.syncState { Text(why).foregroundStyle(.yellow) }130 else { Text("Seuls les changements sont transmis. Les fichiers audio ne sont jamais téléchargés par la synchronisation, sauf pour les albums et listes que vous gardez hors ligne.") }131 }132 Section("À propos") {133 HStack { Text("Version"); Spacer(); Text("\(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "") (\(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? ""))").foregroundStyle(Color.spMuted) }134 HStack { Text("Serveur"); Spacer(); Text(env.api.baseURL.host ?? "").foregroundStyle(Color.spMuted) }135 }136 }137 .scrollContentBackground(.hidden).background(Color.spBackground)138 .navigationTitle("Réglages")139 }140}141142struct NetworkSettingsView: View {143 @Environment(AppEnvironment.self) private var env144 var body: some View {145 @Bindable var settings = env.settings146 List {147 Section {148 Toggle("Diffusion en Wi-Fi uniquement", isOn: Binding(get: { !settings.transfer.streamOnCellular }, set: { settings.transfer.streamOnCellular = !$0 }))149 Picker("Qualité en Wi-Fi", selection: $settings.transfer.streamQualityWifi) { qualities }150 Picker("Qualité en cellulaire", selection: $settings.transfer.streamQualityCellular) { qualities }.disabled(!settings.transfer.streamOnCellular)151 } header: { Text("Diffusion") } footer: {152 Text("La musique téléchargée se lit toujours depuis l'appareil, sans données. En mode Données réduites, la diffusion passe en AAC.")153 }154 Section {155 Toggle("Téléchargements en Wi-Fi uniquement", isOn: Binding(get: { !settings.transfer.downloadOnCellular }, set: { settings.transfer.downloadOnCellular = !$0 }))156 Toggle("Autoriser les téléchargements cellulaires", isOn: $settings.transfer.downloadOnCellular)157 Picker("Qualité des téléchargements", selection: $settings.transfer.downloadQuality) { qualities }158 Toggle("Télécharger les nouveaux titres des albums et listes gardés hors ligne", isOn: $settings.transfer.autoDownloadPinned)159 Stepper("Transferts simultanés : \(settings.transfer.maxConcurrentDownloads)", value: $settings.transfer.maxConcurrentDownloads, in: 1...4)160 } header: { Text("Téléchargements") } footer: {161 Text("Sur réseau cellulaire, une confirmation est demandée au-delà de \(Format.bytes(settings.transfer.cellularConfirmBytes)). Les téléchargements n'ont jamais lieu en mode Données réduites. Le nombre de transferts simultanés s'applique au prochain lancement. iOS décide du rythme des transferts quand l'app est en arrière-plan.")162 }163 }164 .tint(Color.spEmber)165 .scrollContentBackground(.hidden).background(Color.spBackground)166 .navigationTitle("Données cellulaires")167 }168 @ViewBuilder private var qualities: some View {169 Text("Originale").tag(Quality.original)170 Text("AAC 256 kbit/s").tag(Quality.compact)171 }172}173174struct AudioSettingsView: View {175 @Environment(AppEnvironment.self) private var env176 @State private var formats: [(String, Int)] = []177 var body: some View {178 let route = env.audioSession.route179 List {180 Section {181 info("Originale", "Le fichier tel qu'il est stocké sur MacLustr (FLAC, ALAC, WAV, AIFF, MP3, AAC), décodé par iOS sans conversion par l'app.")182 info("AAC 256 kbit/s", "Un rendu préparé à la demande par MacLustr, environ cinq fois plus léger qu'un FLAC. L'original n'est jamais modifié.")183 } header: { Text("Qualités") } footer: { Text("Le choix se fait dans « Données cellulaires et téléchargements », séparément pour le Wi-Fi, le cellulaire et les téléchargements.") }184 if !formats.isEmpty {185 Section("Formats de votre bibliothèque") { ForEach(formats, id: \.0) { f in HStack { Text(f.0); Spacer(); Text("\(f.1) titre\(f.1 > 1 ? "s" : "")").foregroundStyle(Color.spMuted) } } }186 }187 Section {188 HStack { Text("Sortie"); Spacer(); Label(route.name.isEmpty ? "—" : route.name, systemImage: route.symbol).foregroundStyle(Color.spMuted) }189 HStack { Text("Fréquence de la sortie"); Spacer(); Text(route.sampleRate > 0 ? "\(String(format: "%.1f", route.sampleRate / 1000)) kHz" : "—").foregroundStyle(Color.spMuted) }190 } header: { Text("Chemin audio actuel") } footer: {191 Text("L'app affiche le format du fichier lu et l'état de la sortie. Elle ne prétend pas à une lecture « bit-perfect » : iOS peut rééchantillonner selon la sortie, et le Bluetooth recompresse toujours le son. Pour une fréquence supérieure à 48 kHz, un convertisseur USB externe est nécessaire.")192 }193 Section {194 info("Enchaînement sans pause", "Le titre suivant est préparé pendant la lecture ; iOS enchaîne les deux fichiers sans temps de chargement.")195 info("Égaliseur, fondu enchaîné, normalisation", "Non proposés dans cette version : ils imposeraient de traiter le signal dans l'app et de renoncer à la lecture directe par le système.")196 } header: { Text("Traitements") }197 }198 .scrollContentBackground(.hidden).background(Color.spBackground)199 .navigationTitle("Qualité audio")200 .task {201 var by: [String: Int] = [:]202 for t in await env.db.allTracks() { by[t.formatDescription, default: 0] += 1 }203 formats = by.sorted { $0.value > $1.value }.prefix(8).map { ($0.key, $0.value) }204 }205 }206 private func info(_ title: String, _ text: String) -> some View {207 VStack(alignment: .leading, spacing: 3) { Text(title); Text(text).font(.footnote).foregroundStyle(Color.spMuted) }208 }209}210