diff --git a/Apple/App/BurrowApp.swift b/Apple/App/BurrowApp.swift index 3725480..fc05084 100644 --- a/Apple/App/BurrowApp.swift +++ b/Apple/App/BurrowApp.swift @@ -30,8 +30,5 @@ struct PermissionView: View { VStack { Text(verbatim: "Status is \(configuration.status)") } - .onAppear { - configuration.update() - } } } diff --git a/Apple/App/ContentView.swift b/Apple/App/ContentView.swift index 757665c..aa92046 100644 --- a/Apple/App/ContentView.swift +++ b/Apple/App/ContentView.swift @@ -1,13 +1,14 @@ import SwiftUI struct ContentView: View { - @State private var connectedHackClubNetwork = false - + + @ObservedObject var viewModel = NetworkConfiguration() + var body: some View { VStack(alignment: .leading) { HStack { - Text("Networks") + Text(verbatim: "Networks \(viewModel.model.status)") .font(.title3) Spacer() Image(systemName: "badge.plus.radiowaves.forward") @@ -21,10 +22,30 @@ struct ContentView: View { .padding(.top, 2) .font(.subheadline.weight(.bold)) HStack { - Image("hackClubLogo") - .resizable() - .frame(width: 32, height: 32) - .cornerRadius(100) + if (viewModel.status == .unknown) { + + + Image("hackClubLogo") + .resizable() + .frame(width: 32, height: 32) + .cornerRadius(100).onTapGesture { + viewModel.connectToBurrow() + print(viewModel.status) + } + + } else if (viewModel.status == .loading) { + ZStack { + Image("hackClubLogo") + .resizable() + .frame(width: 32, height: 32) + .cornerRadius(100) + .overlay(Color.white.opacity(0.6).cornerRadius(100)) + + ProgressView() + .progressViewStyle(CircularProgressViewStyle()) + .scaleEffect(0.6) + } + } VStack(alignment: .leading) { Text("Hack Club Network") @@ -35,7 +56,7 @@ struct ContentView: View { .font(.caption2) .foregroundColor(.blue) }.onTapGesture { - connectedHackClubNetwork = true + print(true) } } } diff --git a/Apple/App/Model.swift b/Apple/App/Model.swift new file mode 100644 index 0000000..68d63fd --- /dev/null +++ b/Apple/App/Model.swift @@ -0,0 +1,42 @@ +// +// MemoryGame.swift +// Memorize +// +// Created by Thomas Stubblefield on 3/12/23. +// + +import Foundation + +struct Model { + + var status: Status = .unknown + + mutating func connectToBurrow() { + print("let's get this working") + status = .valid + print(status) + } +} + +enum Status: CustomStringConvertible { + case unknown + case blank + case valid + case error + case loading + + var description: String { + switch self { + case .unknown: + return "Unknown" + case .blank: + return "Blank" + case .valid: + return "Valid" + case .loading: + return "Loading" + default: + return "Default" + } + } +} diff --git a/Apple/App/NetworkConfiguration.swift b/Apple/App/NetworkConfiguration.swift index 9bf9390..89bc601 100644 --- a/Apple/App/NetworkConfiguration.swift +++ b/Apple/App/NetworkConfiguration.swift @@ -3,26 +3,13 @@ import NetworkExtension @MainActor class NetworkConfiguration: ObservableObject { - enum Status: CustomStringConvertible { - case unknown - case blank - case valid - case error - - var description: String { - switch self { - case .unknown: - return "Unknown" - case .blank: - return "Blank" - case .valid: - return "Valid" - default: - return "Default" - } - } + func connectToBurrow() { + objectWillChange.send() + model.connectToBurrow() } + @Published var model = Model() + @Published var status: Status = .unknown @@ -32,6 +19,25 @@ class NetworkConfiguration: ObservableObject { } + func connectToNetwork() { + print(self.status) + self.status = .loading + print(self.status) + + DispatchQueue.main.asyncAfter(deadline: .now() + 3) { + let random = Int.random(in: 0...1) + if random == 0 { + self.status = .valid + print(self.status) + + } else { + self.status = .error + print(self.status) + + } + } + } + func update() { Task { do { diff --git a/Apple/Burrow.xcodeproj/project.pbxproj b/Apple/Burrow.xcodeproj/project.pbxproj index 57298cf..be8f359 100644 --- a/Apple/Burrow.xcodeproj/project.pbxproj +++ b/Apple/Burrow.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 43E50D6D29FA050600BD2280 /* FluidMenuBarExtra in Frameworks */ = {isa = PBXBuildFile; platformFilters = (macos, ); productRef = 43E50D6C29FA050600BD2280 /* FluidMenuBarExtra */; }; 43EBDB2B29FD7557005D8CFF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EBDB2A29FD754A005D8CFF /* AppDelegate.swift */; }; 43EBDB2D29FD759E005D8CFF /* NetworkConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EBDB2C29FD759E005D8CFF /* NetworkConfiguration.swift */; }; + 43EBDB2F29FDE85F005D8CFF /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EBDB2E29FDE85F005D8CFF /* Model.swift */; }; D020F65829E4A697002790F6 /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D020F65729E4A697002790F6 /* PacketTunnelProvider.swift */; }; D020F65D29E4A697002790F6 /* BurrowNetworkExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = D020F65329E4A697002790F6 /* BurrowNetworkExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; D05B9F7629E39EEC008CB1F9 /* BurrowApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05B9F7529E39EEC008CB1F9 /* BurrowApp.swift */; }; @@ -44,6 +45,7 @@ /* Begin PBXFileReference section */ 43EBDB2A29FD754A005D8CFF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 43EBDB2C29FD759E005D8CFF /* NetworkConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConfiguration.swift; sourceTree = ""; }; + 43EBDB2E29FDE85F005D8CFF /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; D020F63D29E4A1FF002790F6 /* Identity.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Identity.xcconfig; sourceTree = ""; }; D020F64029E4A1FF002790F6 /* Compiler.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Compiler.xcconfig; sourceTree = ""; }; D020F64229E4A1FF002790F6 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -133,6 +135,7 @@ 43EBDB2A29FD754A005D8CFF /* AppDelegate.swift */, D05B9F7729E39EEC008CB1F9 /* ContentView.swift */, 43EBDB2C29FD759E005D8CFF /* NetworkConfiguration.swift */, + 43EBDB2E29FDE85F005D8CFF /* Model.swift */, D05B9F7929E39EED008CB1F9 /* Assets.xcassets */, D020F66829E4AA74002790F6 /* App-iOS.entitlements */, D020F66929E4AA74002790F6 /* App-macOS.entitlements */, @@ -254,6 +257,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 43EBDB2F29FDE85F005D8CFF /* Model.swift in Sources */, 43EBDB2B29FD7557005D8CFF /* AppDelegate.swift in Sources */, D05B9F7829E39EEC008CB1F9 /* ContentView.swift in Sources */, D05B9F7629E39EEC008CB1F9 /* BurrowApp.swift in Sources */,