From abab6bb844323e48e0b298319296da1d1243c8bf Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Tue, 21 Dec 2021 23:19:42 -0500 Subject: [PATCH] Put uuids in the iCloud data about each destination and start building the view for a specific destination to control the connection, listening and debug. --- ListenerGS.xcodeproj/project.pbxproj | 4 ++++ ListenerGS/DestinationsView.swift | 2 +- ListenerGS/GSDestinations.swift | 31 ++++++++++++++++++++++---- ListenerGS/GSView.swift | 33 ++++++++++++++++++++++++++++ ListenerGS/Info.plist | 2 +- 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 ListenerGS/GSView.swift diff --git a/ListenerGS.xcodeproj/project.pbxproj b/ListenerGS.xcodeproj/project.pbxproj index 1c849bc..9ad7a0d 100644 --- a/ListenerGS.xcodeproj/project.pbxproj +++ b/ListenerGS.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 9D6F27092728EF410089585E /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D6F27082728EF410089585E /* MainView.swift */; }; 9DCCDACC271FB87100F311DF /* GSDestinations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DCCDACB271FB87100F311DF /* GSDestinations.swift */; }; 9DD67CF02728F5B700243FC6 /* DestinationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DD67CEF2728F5B700243FC6 /* DestinationsView.swift */; }; + 9DD890602772D3B20084A894 /* GSView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DD8905F2772D3B20084A894 /* GSView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -80,6 +81,7 @@ 9DCCDACB271FB87100F311DF /* GSDestinations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GSDestinations.swift; sourceTree = ""; }; 9DD67CEF2728F5B700243FC6 /* DestinationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DestinationsView.swift; sourceTree = ""; }; 9DD8905E27726C140084A894 /* ListenerGS Icon.pxm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ListenerGS Icon.pxm"; sourceTree = ""; }; + 9DD8905F2772D3B20084A894 /* GSView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GSView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -139,6 +141,7 @@ 9D6F27082728EF410089585E /* MainView.swift */, 9DD67CEF2728F5B700243FC6 /* DestinationsView.swift */, 9DCCDACB271FB87100F311DF /* GSDestinations.swift */, + 9DD8905F2772D3B20084A894 /* GSView.swift */, 9D5155F426A1EF7B0075EBC7 /* ContentView.swift */, 9D6ED239271E6BD600D773CD /* SpeechForwarder.swift */, 9DD8905E27726C140084A894 /* ListenerGS Icon.pxm */, @@ -370,6 +373,7 @@ 9DD67CF02728F5B700243FC6 /* DestinationsView.swift in Sources */, 9D51565626A36B410075EBC7 /* Socket.swift in Sources */, 9D51565326A36B410075EBC7 /* yudpsocket.c in Sources */, + 9DD890602772D3B20084A894 /* GSView.swift in Sources */, 9D51565226A36B410075EBC7 /* Result.swift in Sources */, 9D5155F526A1EF7B0075EBC7 /* ContentView.swift in Sources */, 9D6ED23A271E6BD600D773CD /* SpeechForwarder.swift in Sources */, diff --git a/ListenerGS/DestinationsView.swift b/ListenerGS/DestinationsView.swift index 5738d49..1d0bca7 100644 --- a/ListenerGS/DestinationsView.swift +++ b/ListenerGS/DestinationsView.swift @@ -18,7 +18,7 @@ struct DestinationsView: View { var body: some View { List { ForEach(destinations.dests) { destination in - NavigationLink(destination: Text(destination.ipAddress)) { + NavigationLink(destination: GSView(ipAddress: destination.ipAddress)) { Text(destination.ipAddress) } } diff --git a/ListenerGS/GSDestinations.swift b/ListenerGS/GSDestinations.swift index c9ce917..041c3ff 100644 --- a/ListenerGS/GSDestinations.swift +++ b/ListenerGS/GSDestinations.swift @@ -10,7 +10,24 @@ import Foundation struct Destination: Identifiable, Hashable { let ipAddress : String - let id = UUID() + let id : UUID + + init(ipAddress: String) + { + self.ipAddress = ipAddress + self.id = UUID() + } + + init(ipAddress: String, uuid: String) + { + self.ipAddress = ipAddress + let idMaybe = UUID(uuidString: uuid) + if let id = idMaybe { + self.id = id + } else { + self.id = UUID() + } + } } class GSDestinations : ObservableObject { @@ -20,6 +37,7 @@ class GSDestinations : ObservableObject { static let kDestinationKey = "destinations" static let kDestinationIpAddress = "ip_address" + static let kDestinationUUID = "uuid" public func onDelete(offsets: IndexSet) { dests.remove(atOffsets: offsets) @@ -34,8 +52,9 @@ class GSDestinations : ObservableObject { } public func onAdd(ipAddress: String) { - dests.append(Destination(ipAddress: ipAddress)) - storedDestinations.append([GSDestinations.kDestinationIpAddress : ipAddress]) + let newDestination = Destination(ipAddress: ipAddress) + dests.append(newDestination) + storedDestinations.append([GSDestinations.kDestinationIpAddress : ipAddress, GSDestinations.kDestinationUUID : newDestination.id.uuidString]) saveDestinations() } @@ -46,7 +65,11 @@ class GSDestinations : ObservableObject { for value in storedDestinations { if let ipAddress = (value as! [String:String])[GSDestinations.kDestinationIpAddress] { - dests.append(Destination(ipAddress: ipAddress)) + if let id = (value as! [String:String])[GSDestinations.kDestinationUUID] { + dests.append(Destination(ipAddress: ipAddress, uuid: id)) + } else { + dests.append(Destination(ipAddress: ipAddress)) + } } else { storedDestinations = [] dests = [] diff --git a/ListenerGS/GSView.swift b/ListenerGS/GSView.swift new file mode 100644 index 0000000..806f9bd --- /dev/null +++ b/ListenerGS/GSView.swift @@ -0,0 +1,33 @@ +// +// GSView.swift +// ListenerGS +// +// Created by Jeremy Rand on 2021-12-21. +// + +import SwiftUI + +struct GSView: View { + private let ipAddress : String + + var body: some View { + Text(ipAddress) + Button("Connect to \(ipAddress)") { + + } + .padding() + .background(Color(red: 0, green: 0, blue: 0.5)) + .foregroundColor(.white) + .clipShape(Capsule()) + } + + init(ipAddress : String) { + self.ipAddress = ipAddress + } +} + +struct GSView_Previews: PreviewProvider { + static var previews: some View { + GSView(ipAddress: "192.168.1.1") + } +} diff --git a/ListenerGS/Info.plist b/ListenerGS/Info.plist index 8dbd246..79849ac 100644 --- a/ListenerGS/Info.plist +++ b/ListenerGS/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 249 + 278 LSApplicationCategoryType public.app-category.utilities LSRequiresIPhoneOS