iOS: export/import stem playlists and sound settings
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9646b4c010
commit
4e2816673d
3 files changed
+144
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
/// A Settings.app row that pushes [route]: icon, title, grey value, chevron.
|
||||
private struct NavCell: View {
|
||||
@@ -147,6 +148,11 @@ struct SettingsScreen: View {
|
||||
NavCell(title: "Cache & Downloads", value: gb(g.cache.usage.cachedBytes), icon: "externaldrive.fill", iconBg: 0x8E8E93, route: .Storage)
|
||||
ToggleCell(title: "Download on Wi-Fi Only", icon: "arrow.down.circle.fill", iconBg: 0x30B0C7, isOn: $s.downloadsWifiOnly)
|
||||
} header: { Header(text: "Storage") }
|
||||
Section {
|
||||
BackupCells()
|
||||
} header: { Header(text: "Backup") } footer: {
|
||||
Footer(text: "Stem playlists, their mixes and sound settings. Tokens and server addresses are left out. Save to iCloud Drive from the Files sheet.")
|
||||
}
|
||||
Section {
|
||||
NavCell(title: "Appearance", value: s.theme.label, icon: "paintbrush.fill", iconBg: 0x007AFF, route: .Appearance)
|
||||
} header: { Header(text: "Display") } footer: {
|
||||
@@ -159,6 +165,42 @@ struct SettingsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct BackupCells: View {
|
||||
private var g: AppGraph { .shared }
|
||||
@State private var doc = ExportDocument()
|
||||
@State private var exporting = false
|
||||
@State private var importing = false
|
||||
@State private var message: String?
|
||||
@Environment(\.palette) private var p
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
do { doc = ExportDocument(data: try StemifyExport.capture(g.stemPlaylists, g.settings).encoded()); exporting = true }
|
||||
catch { message = error.localizedDescription }
|
||||
} label: { ValueCell(title: "Export", value: "\(g.stemPlaylists.lists.count) playlists", icon: "square.and.arrow.up", iconBg: 0x007AFF) }
|
||||
.themedRow()
|
||||
Button { importing = true } label: { ValueCell(title: "Import", value: nil, icon: "square.and.arrow.down", iconBg: 0x34C759) }
|
||||
.themedRow()
|
||||
.fileExporter(isPresented: $exporting, document: doc, contentType: .json, defaultFilename: "Stemify \(Date().formatted(.iso8601.year().month().day()))") { r in
|
||||
if case .failure(let e) = r { message = e.localizedDescription }
|
||||
}
|
||||
.fileImporter(isPresented: $importing, allowedContentTypes: [.json]) { r in
|
||||
do {
|
||||
let url = try r.get()
|
||||
let scoped = url.startAccessingSecurityScopedResource()
|
||||
defer { if scoped { url.stopAccessingSecurityScopedResource() } }
|
||||
let x = try StemifyExport.decode(Data(contentsOf: url))
|
||||
let n = g.stemPlaylists.merge(x.playlists)
|
||||
x.apply(to: g.settings)
|
||||
message = "Imported \(n) playlist\(n == 1 ? "" : "s") and your sound settings."
|
||||
} catch { message = error.localizedDescription }
|
||||
}
|
||||
.alert("Backup", isPresented: Binding(get: { message != nil }, set: { if !$0 { message = nil } })) {
|
||||
Button("OK", role: .cancel) {}
|
||||
} message: { Text(message ?? "") }
|
||||
}
|
||||
}
|
||||
|
||||
// ---- plex -----------------------------------------------------------------------------------
|
||||
|
||||
struct PlexAccountScreen: View {
|
||||
|
||||
Reference in new issue
Block a user