RootView.swift (1664B)
1 // SPDX-License-Identifier: GPL-2.0-only 2 import SwiftUI 3 4 struct RootView: View { 5 @Environment(AppModel.self) private var model 6 @State private var tab = LaunchOptions.value("-tab") ?? "dives" 7 8 var body: some View { 9 switch model.phase { 10 case .launching: 11 ProgressView() 12 case .signedOut: 13 LoginView() 14 case .ready: 15 TabView(selection: $tab) { 16 DiveListView() 17 .tabItem { Label("Dives", systemImage: "water.waves") } 18 .tag("dives") 19 SitesView() 20 .tabItem { Label("Sites", systemImage: "map") } 21 .tag("sites") 22 PlannerView() 23 .tabItem { Label("Planning", systemImage: "point.topleft.down.to.point.bottomright.curvepath") } 24 .tag("plan") 25 StatsView() 26 .tabItem { Label("Statistics", systemImage: "chart.bar") } 27 .tag("stats") 28 SettingsView() 29 .tabItem { Label("Settings", systemImage: "gearshape") } 30 .tag("settings") 31 } 32 } 33 } 34 } 35 36 /// Launch options for screenshots: `-demo`, `-tab sites|stats|settings`, `-showDive 11`, `-edit`. 37 enum LaunchOptions { 38 static func value(_ name: String) -> String? { 39 let arguments = ProcessInfo.processInfo.arguments 40 guard let index = arguments.firstIndex(of: name), index + 1 < arguments.count else { return nil } 41 return arguments[index + 1] 42 } 43 44 static func flag(_ name: String) -> Bool { ProcessInfo.processInfo.arguments.contains(name) } 45 }