PulseCanvas / app / visionOS / VisionInfoView.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | /// Onboarding, backup, iCloud and legal information, opened from the info button. |
| 4 | struct VisionInfoView: View { |
| 5 | @ObservedObject var session: VisionSession |
| 6 | let close: () -> Void |
| 7 | let replayOnboarding: () -> Void |
| 8 | @State private var page = Page.onboarding |
| 9 | private enum Page { case onboarding, backup, cloud, legal } |
| 10 | |
| 11 | var body: some View { |
| 12 | VStack(alignment: .leading, spacing: 24) { |
| 13 | HStack { |
| 14 | Label("PulseCanvas Studio", systemImage: "waveform").font(.title2.bold()) |
| 15 | Spacer() |
| 16 | Button("Done", action: close).accessibilityIdentifier("closeVisionInfoButton") |
| 17 | } |
| 18 | Picker("Information", selection: $page) { |
| 19 | Text("Onboarding").tag(Page.onboarding) |
| 20 | Text("Backup & Restore").tag(Page.backup) |
| 21 | Text("iCloud").tag(Page.cloud) |
| 22 | Text("Legal & Credits").tag(Page.legal) |
| 23 | }.pickerStyle(.segmented) |
| 24 | ScrollView { |
| 25 | if page == .onboarding { onboarding } |
| 26 | else if page == .backup { |
| 27 | UserBackupView(currentProject: { |
| 28 | let editor = session.editor |
| 29 | return try editor.project.portableData(duration: editor.transport.duration, scene: editor.selectedScene) |
| 30 | }, prepare: { session.suspend() }, openProject: { data in |
| 31 | do { |
| 32 | let project = try VisionProject.openPortable(data) |
| 33 | Task { await session.editor.replaceProject(project) } |
| 34 | } catch { session.editor.message = error.localizedDescription } |
| 35 | }) |
| 36 | .disabled(session.editor.loading) |
| 37 | } |
| 38 | else if page == .cloud { |
| 39 | CloudSyncView(prepare: { session.suspend() }, openProject: { data in |
| 40 | do { |
| 41 | let project = try VisionProject.openPortable(data) |
| 42 | Task { await session.editor.replaceProject(project) } |
| 43 | } catch { session.editor.message = error.localizedDescription } |
| 44 | }).disabled(session.editor.loading) |
| 45 | } |
| 46 | else { legal } |
| 47 | }.scrollBounceBehavior(.basedOnSize) |
| 48 | }.padding(32).frame(width: 760, height: 730) |
| 49 | } |
| 50 | |
| 51 | private var onboarding: some View { |
| 52 | VStack(alignment: .leading, spacing: 12) { |
| 53 | Button("Welcome to PulseCanvas Studio", systemImage: "sparkles") { |
| 54 | replayOnboarding() |
| 55 | }.accessibilityIdentifier("settingsWelcomePulseCanvas") |
| 56 | Text("See the onboarding again, from the beginning.").font(.callout).foregroundStyle(.secondary) |
| 57 | }.frame(maxWidth: .infinity, alignment: .leading) |
| 58 | } |
| 59 | |
| 60 | private var legal: some View { |
| 61 | VStack(alignment: .leading, spacing: 20) { |
| 62 | Link("Source code on GitHub", destination: URL(string: "https://github.com/projectatomai/pulsecanvas")!) |
| 63 | Text(Bundle.main.url(forResource: "PulseCanvas-LICENSE", withExtension: "txt", subdirectory: "Legal") |
| 64 | .flatMap { try? String(contentsOf: $0, encoding: .utf8) } ?? "License unavailable") |
| 65 | .font(.body).textSelection(.enabled) |
| 66 | }.frame(maxWidth: .infinity, alignment: .leading) |
| 67 | } |
| 68 | } |