SPB Git

Repository Public

DebugLaunch.swift 6.9 KB 156 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/DebugLaunch.swift8// Module           : Sources9// Repository       : https://git.spboucher.ai/qyvora10// Project Website  : Not specified11// Created          : 2026-12-0412// Last Modified    : 2026-12-0413//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041#if DEBUG42import SwiftUI43import QyvoraBenchmarks44import QyvoraMigration4546/// DEBUG-only launch arguments that open a given screen directly (screenshots, UI review). Not compiled in Release.47///48///   -QYScreen <name>       boot | selftest-failed | privacy-cover | onboarding | locked | wallet | shield | activity49///                          | settings | endpoints | endpoint-list | appearance | about | crypto | algorithm50///                          | benchmarks | migration | gallery51///   -QYPage <0…3>          onboarding page52///   -QYEndpointKind <k>    esplora | ethereumRPC | ethereumIndexer | priceAPI | priceCheckAPI   (with endpoint-list)53///   -QYNetwork <n>         testnet | signet | mainnet | sepolia                  (with endpoint-list)54///   -QYAlgorithm <name>    catalogue name, e.g. ML-KEM-768                       (with algorithm)55///   -QYChain <c>           bitcoin | ethereum                                    (with migration)56///   -QYBenchFamily <f,…>   mlkem,mldsa,slhdsa,hash,symmetric,kdf,ntt,secp256k1   (with benchmarks)57///   -QYBenchAutorun YES    starts the run when the benchmark screen opens58///   -QYScrollTo <id>       migration: available | planned | awaitingProtocol ; benchmarks: results-<family> | environment59///                          | energy ; crypto: an algorithm name ; -QYScrollDelay <seconds> (default 0.8)60///   Wallet screens and `-QYDebugWallet`: see Wallet/DebugWalletLaunch.swift.61///   -QYGallery <section>   amounts | entry | seed | seed-entry | pin | password | charts | rows | qr | scanner | feedback62enum DebugLaunch {63    static var defaults: UserDefaults { .standard }64    static var screen: String? { defaults.string(forKey: "QYScreen") }65    static var page: Int { defaults.integer(forKey: "QYPage") }66    static var gallerySection: String { defaults.string(forKey: "QYGallery") ?? "amounts" }6768    @MainActor69    static func makeModel() -> AppModel {70        // first thing of a launch: what a previous tour wrote to the defaults must not choose this launch's screen71        DebugNavigator.clearStaleCommands()72        let model: AppModel73        switch screen {74        case "selftest-failed": model = AppModel(selfTestRun: { false })75        case "boot": model = AppModel(selfTestRun: { Thread.sleep(forTimeInterval: 3600); return true })76        default: model = AppModel()77        }78        switch screen {79        case nil, "onboarding", "boot", "selftest-failed", "privacy-cover": model.route = .onboarding80        case "locked": model.route = .locked81        default: model.route = .main82        }83        return model84    }8586    static var initialTab: MainTab {87        switch screen {88        case "shield": return .shield89        case "activity", "tx-detail": return .activity90        case nil: return .wallet91        case let name? where walletScreens.contains(name): return .wallet92        default: return .settings93        }94    }9596    static var initialSettingsPath: NavigationPath {97        var path = NavigationPath()98        switch screen {99        case "endpoints":100            path.append(SettingsRoute.endpoints)101        case "endpoint-list":102            let kind = EndpointListID.Kind(rawValue: defaults.string(forKey: "QYEndpointKind") ?? "") ?? .esplora103            let network = kind == .priceAPI || kind == .priceCheckAPI ? "" : (defaults.string(forKey: "QYNetwork") ?? (kind == .esplora ? "testnet" : "sepolia"))104            path.append(SettingsRoute.endpoints)105            path.append(SettingsRoute.endpointList(EndpointListID(kind: kind, network: network)))106        case "appearance":107            path.append(SettingsRoute.appearance)108        case "about":109            path.append(SettingsRoute.about)110        case "crypto":111            path.append(EngineRoute.cryptography)112        case "algorithm":113            path.append(EngineRoute.cryptography)114            path.append(EngineRoute.algorithm(defaults.string(forKey: "QYAlgorithm") ?? "ML-KEM-768"))115        case "benchmarks":116            path.append(EngineRoute.benchmarks)117        case "migration":118            path.append(EngineRoute.migration)119        default:120            break121        }122        return path123    }124125    static var migrationChain: MigrationEngine.Chain {126        MigrationEngine.Chain(rawValue: defaults.string(forKey: "QYChain") ?? "") ?? .bitcoin127    }128129    static var benchFamilies: Set<BenchmarkFamily>? {130        guard let text = defaults.string(forKey: "QYBenchFamily") else { return nil }131        let families = text.split(separator: ",").compactMap { BenchmarkFamily(rawValue: String($0)) }132        return families.isEmpty ? nil : Set(families)133    }134135    static var benchAutorun: Bool { defaults.bool(forKey: "QYBenchAutorun") }136137    static var scrollTarget: String? { defaults.string(forKey: "QYScrollTo") }138    static var scrollDelay: Double { defaults.object(forKey: "QYScrollDelay") == nil ? 0.8 : defaults.double(forKey: "QYScrollDelay") }139}140141/// Scrolls its content to `-QYScrollTo <id>` after `-QYScrollDelay <seconds>` (default 0.8).142struct DebugScroll<Content: View>: View {143    @ViewBuilder let content: Content144145    var body: some View {146        ScrollViewReader { proxy in147            content.task(id: DebugNavigator.shared.serial) {148                guard let target = DebugLaunch.scrollTarget else { return }149                try? await Task.sleep(for: .seconds(DebugLaunch.scrollDelay))150                proxy.scrollTo(target, anchor: .top)151            }152        }153    }154}155#endif156
Files main
Menu

Theme