PulseCanvas / app / Sources / PulseCanvas / ExportOverlayView.swift
| 1 | import AppKit |
| 2 | import SwiftUI |
| 3 | |
| 4 | @MainActor |
| 5 | struct ExportOverlayView: View { |
| 6 | @ObservedObject var exporter: SocialExportController |
| 7 | @State private var showSuccess = false |
| 8 | private let accent = Color(red: 0.95, green: 0.68, blue: 0.55) |
| 9 | |
| 10 | var body: some View { |
| 11 | ZStack { |
| 12 | if exporter.isExporting { |
| 13 | Color.black.opacity(0.82) |
| 14 | VStack(spacing: 22) { |
| 15 | Text("Creating your video").font(.system(size: 26, weight: .semibold, design: .rounded)) |
| 16 | if let preview = exporter.framePreview { |
| 17 | Image(decorative: preview, scale: 1).resizable().scaledToFit() |
| 18 | .frame(maxHeight: 240).clipShape(RoundedRectangle(cornerRadius: 10)) |
| 19 | .accessibilityLabel("Current rendered frame") |
| 20 | } else { |
| 21 | ProgressView().controlSize(.large).frame(height: 120) |
| 22 | } |
| 23 | Text(exporter.status).font(.system(size: 17, weight: .medium)).monospacedDigit() |
| 24 | ProgressView(value: exporter.progress).progressViewStyle(.linear).tint(accent) |
| 25 | .scaleEffect(x: 1, y: 2).accessibilityLabel("Video export progress") |
| 26 | HStack { |
| 27 | if exporter.totalFrames > 0 { |
| 28 | Text("\(exporter.renderedFrames.formatted()) / \(exporter.totalFrames.formatted()) frames") |
| 29 | } |
| 30 | Spacer() |
| 31 | Text("\(Int(exporter.progress * 100))%").monospacedDigit() |
| 32 | }.font(.system(size: 13)).foregroundStyle(.secondary) |
| 33 | if let remaining = exporter.estimatedSecondsRemaining { |
| 34 | Text("About \(remainingTime(remaining)) remaining · \(exporter.framesPerSecond.formatted(.number.precision(.fractionLength(1)))) frames/s") |
| 35 | .font(.system(size: 14, weight: .medium)).monospacedDigit().foregroundStyle(accent) |
| 36 | } else if exporter.renderedFrames < exporter.totalFrames { |
| 37 | Text("Estimating time remaining…").font(.system(size: 14)).foregroundStyle(.secondary) |
| 38 | } |
| 39 | Button("Cancel export") { exporter.cancel() } |
| 40 | .buttonStyle(StudioButtonStyle(compact: true)) |
| 41 | .disabled(exporter.cancellationRequested) |
| 42 | }.padding(.horizontal, 60).padding(.vertical, 32) |
| 43 | } else if showSuccess, let url = exporter.exportedURL { |
| 44 | VStack(spacing: 14) { |
| 45 | Image(systemName: "checkmark.circle.fill").font(.system(size: 36)).foregroundStyle(.green) |
| 46 | Text("Video saved").font(.system(size: 20, weight: .semibold, design: .rounded)) |
| 47 | Text(url.lastPathComponent).font(.system(size: 12)).foregroundStyle(.secondary).lineLimit(2) |
| 48 | Button { NSWorkspace.shared.activateFileViewerSelecting([url]) } label: { |
| 49 | Label("Show in Finder", systemImage: "folder") |
| 50 | }.buttonStyle(StudioButtonStyle(treatment: .primary, compact: true)) |
| 51 | }.padding(28).frame(width: 370) |
| 52 | .background(Color(red: 0.20, green: 0.17, blue: 0.22), in: RoundedRectangle(cornerRadius: 18)) |
| 53 | .overlay(RoundedRectangle(cornerRadius: 18).strokeBorder(.white.opacity(0.15))) |
| 54 | .overlay(alignment: .topTrailing) { |
| 55 | Button { withAnimation { showSuccess = false } } label: { |
| 56 | Image(systemName: "xmark").frame(width: 44, height: 44) |
| 57 | }.buttonStyle(.plain).accessibilityLabel("Dismiss export success") |
| 58 | } |
| 59 | .shadow(color: .black.opacity(0.4), radius: 24, y: 8) |
| 60 | .transition(.opacity.combined(with: .scale(scale: 0.96))) |
| 61 | } |
| 62 | }.frame(maxWidth: .infinity, maxHeight: .infinity) |
| 63 | .onChange(of: exporter.exportedURL) { _, url in withAnimation { showSuccess = url != nil } } |
| 64 | .task(id: exporter.exportedURL) { |
| 65 | guard exporter.exportedURL != nil else { return } |
| 66 | do { try await Task.sleep(for: .seconds(10)) } catch { return } |
| 67 | withAnimation { showSuccess = false } |
| 68 | } |
| 69 | } |
| 70 | private func remainingTime(_ seconds: Double) -> String { |
| 71 | let rounded = max(1, Int(ceil(seconds))) |
| 72 | if rounded >= 3600 { return "\(rounded / 3600)h \((rounded % 3600) / 60)m" } |
| 73 | if rounded >= 60 { return "\(rounded / 60)m \(rounded % 60)s" } |
| 74 | return "\(rounded)s" |
| 75 | } |
| 76 | |
| 77 | } |