summaryrefslogtreecommitdiff
path: root/LearnMapKit/LearnMapKitApp.swift
diff options
context:
space:
mode:
Diffstat (limited to 'LearnMapKit/LearnMapKitApp.swift')
-rw-r--r--LearnMapKit/LearnMapKitApp.swift86
1 files changed, 72 insertions, 14 deletions
diff --git a/LearnMapKit/LearnMapKitApp.swift b/LearnMapKit/LearnMapKitApp.swift
index 62a902f..8132c92 100644
--- a/LearnMapKit/LearnMapKitApp.swift
+++ b/LearnMapKit/LearnMapKitApp.swift
@@ -11,26 +11,60 @@ import ArgumentParser
//https://www.hackingwithswift.com/quick-start/swiftui/how-to-run-code-when-your-app-launches
-
+struct CommandLineArgs: ParsableCommand {
+ @Option(name: .shortAndLong) var hostname: String? = nil
+ @Option(name: .shortAndLong) var port: Int? = nil
+ @Option(name: .shortAndLong) var inputfile: String? = nil
+ @Flag(name: .shortAndLong) var debug:Bool = false
+ @Flag(name: .shortAndLong) var version:Bool = false
+}
@main
struct LearnMapKitApp: App {
-
+ var network_mode = false
+ var file_mode = false
@State var queue: Deque<ADSBLocation> = []
@State var netconfig: NetworkConfigure = NetworkConfigure()
- @StateObject private var flightState = FlightState()
+ @StateObject private var flightState:FlightState = FlightState()
+
+ var default_hostname = "192.168.4.201"
+ var default_port = 30002
+ var default_input_file = ""
init() {
-
print("Init app")
- let ADSBClient = NetADSBDecoder(host: "192.168.4.201", port: 30002)
- /*do {
- try ADSBClient.start()
- } catch let error {
- print("Error: \(error.localizedDescription)")
- ADSBClient.stop()
- }*/
+ //parse arguments
+ //let args = CommandLineArgs.parseOrExit()
+ //flightState.defaultMode()
+ let args = CommandLineArgs.parseOrExit()
+ print(args)
+ print(args.inputfile)
+ //exit(0)
+ //if (true)//
+ if let args = CommandLineArgs.parseNotExit()
+ {
+ if args.hostname != nil {
+ default_hostname = args.hostname!
+ network_mode = true
+ }
+ if args.port != nil {
+ default_port = args.port!
+ network_mode = true
+ }
+
+ if args.inputfile != nil {
+ default_input_file = args.inputfile!
+ file_mode = true
+ }
+ print("Set this")
+
+ }
+
+ //flightState.run()
+
+
+ /*let ADSBClient = NetADSBDecoder(host: default_hostname, port: default_port)
DispatchQueue.global(qos: .background).async {
do {
try ADSBClient.start()
@@ -38,17 +72,41 @@ struct LearnMapKitApp: App {
print("Error: \(error.localizedDescription)")
ADSBClient.stop()
}
- }
+ }*/
}
var body: some Scene {
WindowGroup {
- ContentView(pos_queue: $queue, net_config: $netconfig)
+ ContentView(pos_queue: $queue, net_config: $netconfig).onAppear(perform: {
+ if network_mode {
+ print("network mode")
+ flightState.networkMode(hostname: self.default_hostname, port: self.default_port)
+ } else if (file_mode){
+ print("RUn file mode")
+ flightState.fileMode(filepath: self.default_input_file)
+ } else {
+ print("Run default mode")
+ flightState.defaultMode()
+ }
+ flightState.run()
+ })
}.environmentObject(flightState)
WindowGroup("Network", id: "net-config") {
NetConfigView(net_config: $netconfig)
}
}
-
+}
+
+extension ParsableArguments {
+ static func parseNotExit(
+ _ arguments: [String]? = nil
+ ) -> Self! {
+ do {
+ return try parse(arguments)
+ } catch {
+ print("Ignore error")
+ return nil
+ }
+ }
}