import SwiftUI @main struct ReelWatchApp: App { @StateObject private var model = WatchModel() @Environment(\.scenePhase) private var phase var body: some Scene { WindowGroup { WatchView() .environmentObject(model) .onAppear { model.activate() } } .onChange(of: phase) { _, p in model.setActive(p == .active) } } } struct WatchView: View { @EnvironmentObject var model: WatchModel var body: some View { ZStack { Color.black.ignoresSafeArea() if let f = model.frame { Image(uiImage: f) .resizable() .aspectRatio(contentMode: .fit) .scaleEffect(x: model.front ? -1 : 1, y: 1) // frontale a specchio, come sull'iPhone .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center) .ignoresSafeArea() } else { VStack(spacing: 6) { Image(systemName: model.reachable ? "video" : "iphone.slash") .font(.title2) Text(model.reachable ? "In attesa dell'anteprima" : "Apri Reel sull'iPhone") .font(.footnote) .multilineTextAlignment(.center) } .foregroundStyle(.secondary) } VStack { HStack { if model.recording, let s = model.startedAt { TimelineView(.periodic(from: s, by: 1)) { ctx in Text(mmss(ctx.date.timeIntervalSince(s))) .font(.system(.footnote, design: .monospaced).weight(.semibold)) .padding(.horizontal, 6).padding(.vertical, 2) .background(.red, in: Capsule()) } } else if model.saving { Text("Salvo…") .font(.footnote) .padding(.horizontal, 6).padding(.vertical, 2) .background(.black.opacity(0.6), in: Capsule()) } Spacer() if model.reachable && !model.recording { Button { model.flip() } label: { Image(systemName: "arrow.triangle.2.circlepath.camera") .font(.footnote) .padding(6) .background(.black.opacity(0.6), in: Circle()) } .buttonStyle(.plain) } } Spacer() Button { model.toggleRecord() } label: { ZStack { Circle().stroke(.white, lineWidth: 3).frame(width: 52, height: 52) if model.recording { RoundedRectangle(cornerRadius: 5).fill(.red).frame(width: 22, height: 22) } else { Circle().fill(.red).frame(width: 42, height: 42) } } .opacity(model.reachable && !model.waiting ? 1 : 0.4) } .buttonStyle(.plain) } .padding(.horizontal, 4) } } private func mmss(_ t: TimeInterval) -> String { let s = max(0, Int(t)) return String(format: "%d:%02d", s / 60, s % 60) } }