SPB Git

Repository Public License

DeviceView.swift 4.1 KB 76 lines swift

1// ORIX Secure2// File: App/Sources/Features/DeviceDiagnostics/DeviceView.swift3// Description: Device diagnostics: every reading with its source, and the measurements iOS keeps from apps, shown as unavailable.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import ORIXDesign8import ORIXSecureEngines9import ORIXSecureModel10import SwiftUI1112struct DeviceView: View {13    @Environment(AppModel.self) private var model14    @State private var saved = false15    @State private var showSources = false1617    var body: some View {18        let diagnostics = model.diagnosticsEngine.diagnostics(model.device)19        ScreenScroll {20            if model.device.isSimulator {21                ORIXBanner(.info, title: Text("Running in the Simulator"), message: Text("Battery, Secure Enclave and some hardware readings exist only on a physical device."))22            }23            if !diagnostics.findings.isEmpty { FindingList(findings: diagnostics.findings) }24            ForEach(diagnostics.sections) { section in25                Text(verbatim: section.title).font(.orixTitle).foregroundStyle(ORIX.Palette.textPrimary).accessibilityAddTraits(.isHeader)26                VStack(spacing: 0) {27                    ForEach(Array(section.rows.enumerated()), id: \.element.id) { index, row in28                        VStack(alignment: .leading, spacing: 0) {29                            ReadingRow(label: row.label, value: row.value, note: row.note)30                            if showSources { Text(verbatim: row.source).font(.caption2.monospaced()).foregroundStyle(ORIX.Palette.textTertiary).padding(.bottom, 4) }31                        }32                        .accessibilityIdentifier("reading." + row.id)33                        if index < section.rows.count - 1 { Divider() }34                    }35                }36                .orixCard(padding: ORIX.Space.sm)37            }38            Toggle("Show the API behind each reading", isOn: $showSources).font(.orixCallout).orixCard()39                .accessibilityIdentifier("device.sources")40            ORIXSectionHeader("Not available to apps")41            Text("People expect these from a device health app. iOS does not provide them, so ORIX Secure does not show a number.")42                .font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)43            VStack(alignment: .leading, spacing: 0) {44                ForEach(Array(diagnostics.unavailable.enumerated()), id: \.element.id) { index, item in45                    VStack(alignment: .leading, spacing: 3) {46                        Label { Text(verbatim: item.title) } icon: { Image(systemName: "minus.circle") }.font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)47                        Text(verbatim: item.reason).font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)48                        if let place = item.whereToLook {49                            Label { Text(verbatim: place) } icon: { Image(systemName: "gear") }.font(.orixCaption).foregroundStyle(ORIXAccent.secure.primary)50                        }51                    }52                    .padding(.vertical, 8)53                    .frame(maxWidth: .infinity, alignment: .leading)54                    .accessibilityElement(children: .combine)55                    if index < diagnostics.unavailable.count - 1 { Divider() }56                }57            }58            .orixCard(padding: ORIX.Space.sm)59            .accessibilityElement(children: .contain)60            .accessibilityIdentifier("device.unavailable")61        }62        .navigationTitle("Device")63        .toolbar {64            ToolbarItemGroup(placement: .topBarTrailing) {65                Button {66                    saved = model.store.save(ReportBuilder.device(diagnostics, advice: model.diagnosticsEngine.advice(model.device)))67                    ORIXHaptics.success()68                } label: { Label("Save Report", systemImage: saved ? "checkmark" : "square.and.arrow.down") }69                    .accessibilityIdentifier("device.save")70                Button { model.refresh(); saved = false } label: { Label("Refresh", systemImage: "arrow.clockwise") }71            }72        }73        .accessibilityIdentifier("device")74    }75}76
Files main
Menu

Theme