Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Camera9// File : App/Sources/Features/Settings/SettingsScreen.swift10// Description : Settings: capture preferences, privacy statement, storage,11// permission status, what this device's cameras can really12// do, and about. Every capability line is generated from the13// running camera, not from a model list.14// Module : Features15// Repository : https://git.spboucher.ai/orix-camera16// Project Website : https://www.orixlab.dev17// Created : 2026-11-2118// Last Modified : 2026-11-2119//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : Proprietary, all rights reserved (see license file)85// License File : LICENSE86// Maintainer : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import ORIXDesign94import ORIXImaging95import Photos96import SwiftUI9798struct SettingsScreen: View {99 @Bindable var camera: CameraModel100 let library: MediaLibrary101 @Environment(\.dismiss) private var dismiss102 @State private var itemCount = 0103 @State private var libraryBytes: Int64 = 0104 @State private var freeBytes: Int64 = 0105 @State private var exportBytes: Int64 = 0106 @State private var photosStatus = PHPhotoLibrary.authorizationStatus(for: .addOnly)107 @State private var confirmClear = false108109 var body: some View {110 NavigationStack {111 Form {112 capture113 privacy114 storage115 permissions116 capabilities117 about118 }119 .navigationTitle("Settings")120 .navigationBarTitleDisplayMode(.inline)121 .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() }.accessibilityIdentifier("settings.done") } }122 .onAppear(perform: refresh)123 .confirmationDialog(Text("Clear exported copies?"), isPresented: $confirmClear, titleVisibility: .visible) {124 Button("Clear \(MediaFormat.bytes(exportBytes))", role: .destructive) { library.storage.clearExports(); refresh() }125 Button("Cancel", role: .cancel) {}126 } message: {127 Text("Only the temporary copies made for sharing are removed. Your library is not touched.")128 }129 }130 .environment(\.orixAccent, .camera)131 .tint(ORIXAccent.camera.primary)132 .systemAppearance()133 }134135 private func refresh() {136 let items = library.allItems()137 itemCount = items.count138 libraryBytes = items.reduce(0) { $0 + $1.byteSize }139 freeBytes = library.storage.freeSpace()140 exportBytes = Self.directorySize(library.storage.exportDirectory)141 photosStatus = PHPhotoLibrary.authorizationStatus(for: .addOnly)142 }143144 nonisolated static func directorySize(_ url: URL) -> Int64 {145 let files = (try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: [.fileSizeKey])) ?? []146 return files.reduce(0) { $0 + Int64((try? $1.resourceValues(forKeys: [.fileSizeKey]))?.fileSize ?? 0) }147 }148149 // MARK: Sections150151 private var capture: some View {152 Section {153 Toggle("Save a copy to Photos", isOn: $camera.settings.saveToPhotos).accessibilityIdentifier("settings.saveToPhotos")154 Toggle("16-bit TIFF for computational captures", isOn: $camera.settings.deepComputationalFiles)155 Toggle("Mirror front camera photos", isOn: $camera.settings.mirrorFrontPhotos)156 Toggle("Haptics", isOn: $camera.settings.haptics)157 } header: { Text("Capture") } footer: {158 Text("Captures always go to the ORIX library on this device. With the first option on, a copy is also added to Photos; iOS asks for permission to add (never to read) the first time. Long exposures, light trails, night stacks and bracket fusions are saved as HEIC unless 16-bit TIFF is on.")159 }160 }161162 private var privacy: some View {163 Section {164 Label("No account, no sign-in", systemImage: "person.crop.circle.badge.xmark")165 Label("No network connection: the app contains no networking code", systemImage: "wifi.slash")166 Label("No analytics, no advertising, no tracking", systemImage: "chart.bar.xaxis")167 Label("Photos and videos are processed and stored on this device", systemImage: "iphone")168 Label("Location is never recorded by ORIX Camera", systemImage: "location.slash")169 Toggle("Remove location when exporting", isOn: $camera.settings.stripLocationOnExport).accessibilityIdentifier("settings.stripLocation")170 } header: { Text("Privacy") } footer: {171 Text("Files live in the app's private storage and leave it only when you export, share or save a copy to Photos. Deleting the app deletes its library. The export default applies to files that already carry a location, such as imported ones.")172 }173 }174175 private var storage: some View {176 Section("Storage") {177 LabeledContent("Items in the library", value: itemCount.formatted())178 LabeledContent("Library size", value: MediaFormat.bytes(libraryBytes))179 LabeledContent("Free space on this device", value: MediaFormat.bytes(freeBytes))180 LabeledContent("Exported copies (temporary)", value: MediaFormat.bytes(exportBytes))181 Button("Clear Exported Copies") { confirmClear = true }.disabled(exportBytes == 0).accessibilityIdentifier("settings.clearExports")182 }183 }184185 private func access(_ state: AccessState) -> String {186 switch state {187 case .granted: String(localized: "Allowed")188 case .denied: String(localized: "Not allowed")189 case .undetermined: String(localized: "Not asked yet")190 }191 }192193 private var photosText: String {194 switch photosStatus {195 case .authorized, .limited: String(localized: "Allowed (add only)")196 case .denied, .restricted: String(localized: "Not allowed")197 default: String(localized: "Not asked yet")198 }199 }200201 private var permissions: some View {202 Section {203 LabeledContent("Camera", value: access(camera.backend.cameraAccess()))204 LabeledContent("Microphone", value: access(camera.backend.microphoneAccess()))205 LabeledContent("Photos", value: photosText)206 Button("Open iOS Settings") { if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) } }207 .accessibilityIdentifier("settings.openSystem")208 } header: { Text("Permissions") } footer: {209 Text("The microphone is asked for only when you record video with sound. Photos is asked for only when you save a copy there, and only to add items.")210 }211 }212213 @ViewBuilder private var capabilities: some View {214 Section {215 if camera.lenses.isEmpty {216 Text("The camera has not started yet. Open the camera once to list its capabilities.").foregroundStyle(.secondary)217 }218 ForEach(camera.lenses) { lens in219 LabeledContent {220 Text("f/\(lens.aperture.formatted(.number.precision(.fractionLength(0...2)))) · \(lens.fieldOfView.formatted(.number.precision(.fractionLength(0))))° · ≈\(lens.focalLength35mm.formatted(.number.precision(.fractionLength(0)))) mm")221 } label: {222 Text("\(Self.lensName(lens)) \(lens.label)")223 }224 }225 } header: { Text("Cameras on this device") } footer: {226 Text("Focal lengths are computed from the field of view (35 mm equivalent).")227 }228 if let caps = camera.capabilities {229 Section {230 if caps.isSynthetic {231 Label("Simulator: frames come from a synthetic test scene. There is no optical hardware here.", systemImage: "info.circle").foregroundStyle(.secondary)232 }233 LabeledContent("ISO range", value: "\(ExposureMath.isoLabel(caps.minISO)) – \(ExposureMath.isoLabel(caps.maxISO))")234 LabeledContent("Shutter range", value: "\(ExposureMath.shutterLabel(caps.minExposureDuration)) – \(ExposureMath.shutterLabel(caps.maxExposureDuration)) s")235 LabeledContent("Exposure compensation", value: "\(caps.minExposureBias.formatted(.number.precision(.fractionLength(0...1)))) to \(caps.maxExposureBias.formatted(.number.precision(.fractionLength(0...1)).sign(strategy: .always()))) EV")236 feature("Manual exposure", caps.supportsManualExposure, caps.localizedExplanation(for: .manualExposure))237 feature("Manual focus", caps.supportsManualFocus, caps.localizedExplanation(for: .manualFocus))238 feature("White balance lock", caps.supportsWhiteBalanceLock, caps.localizedExplanation(for: .whiteBalanceLock))239 feature("Flash", caps.hasFlash, caps.localizedExplanation(for: .flash))240 feature("Bayer RAW (DNG)", caps.supportsBayerRAW, caps.localizedExplanation(for: .bayerRAW))241 feature("Apple ProRAW", caps.supportsProRAW, caps.localizedExplanation(for: .proRAW))242 LabeledContent("Exposure bracket", value: caps.maxBracketCount >= 2 ? String(localized: "Up to \(caps.maxBracketCount) frames") : String(localized: "Not offered"))243 LabeledContent("Largest photo", value: "\(MediaFormat.dimensions(width: caps.maxPhotoWidth, height: caps.maxPhotoHeight)) · \(MediaFormat.megapixels(width: caps.maxPhotoWidth, height: caps.maxPhotoHeight))")244 LabeledContent("Digital zoom", value: "\(caps.minZoom.formatted(.number.precision(.fractionLength(0...1))))× – \(caps.maxZoom.formatted(.number.precision(.fractionLength(0...1))))×")245 } header: { Text("Selected camera: \(Self.lensName(caps.lens)) \(caps.lens.label)") } footer: {246 Text("Values are read from the camera in its current configuration. They change with the lens and the mode.")247 }248 Section {249 ForEach(caps.resolutions) { resolution in250 LabeledContent(resolution.resolutionLabel,251 value: caps.frameRates(width: resolution.width, height: resolution.height).map { "\(Int($0))" }.joined(separator: ", ") + " fps")252 }253 LabeledContent("Codecs", value: caps.videoCodecs.map(\.title).joined(separator: ", "))254 feature("Stabilization", caps.supportsVideoStabilization, String(localized: "Not offered by this camera in its formats."))255 feature("ProRes encoder", caps.videoCodecs.contains(.proRes422), caps.localizedExplanation(for: .proRes))256 LabeledContent("10-bit HDR video", value: caps.deviceOffersHDRVideo ? String(localized: "Offered by the camera, not recorded by this version") : String(localized: "Not offered"))257 LabeledContent("Apple Log", value: caps.deviceOffersAppleLog ? String(localized: "Offered by the camera, not recorded by this version") : String(localized: "Not offered"))258 } header: { Text("Video") } footer: {259 Text("ORIX Camera records 8-bit SDR video in this version. Video formats are listed after the camera has been opened in Pro Video.")260 }261 }262 }263264 static func lensName(_ lens: LensDescriptor) -> String {265 switch lens.kind {266 case "ultraWide": String(localized: "Ultra wide")267 case "telephoto": String(localized: "Telephoto")268 case "front": String(localized: "Front")269 case "frontUltraWide": String(localized: "Front ultra wide")270 default: String(localized: "Wide")271 }272 }273274 private func feature(_ title: LocalizedStringKey, _ available: Bool, _ reason: String?) -> some View {275 VStack(alignment: .leading, spacing: 2) {276 HStack {277 Text(title)278 Spacer()279 Label(available ? "Available" : "Unavailable", systemImage: available ? "checkmark.circle.fill" : "minus.circle")280 .labelStyle(.titleAndIcon).font(.subheadline)281 .foregroundStyle(available ? ORIX.Palette.success : ORIX.Palette.textTertiary)282 }283 if !available, let reason, !reason.isEmpty { Text(reason).font(.caption).foregroundStyle(.secondary) }284 }285 .accessibilityElement(children: .combine)286 }287288 private var about: some View {289 Section {290 HStack(spacing: 14) {291 ORIXMark().frame(width: 52, height: 52).padding(6).background(Instrument.body, in: RoundedRectangle(cornerRadius: 14, style: .continuous))292 VStack(alignment: .leading, spacing: 2) {293 Text("ORIX Camera").font(.headline)294 Text("Capture Beyond Ordinary.").font(.subheadline).foregroundStyle(.secondary)295 }296 }297 .accessibilityElement(children: .combine)298 LabeledContent("Version", value: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "–")299 LabeledContent("Build", value: Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "–")300 LabeledContent("Family", value: String(localized: "ORIX: Scan, Calc, Audio, Camera"))301 } header: { Text("About") } footer: {302 Text("© 2026 Simon-Pierre Boucher. All rights reserved. ORIX Camera uses only Apple frameworks; it includes no third-party code.")303 }304 }305}306