Compare commits

..

No commits in common. "master" and "Adding-MIT-License" have entirely different histories.

9 changed files with 17 additions and 63 deletions

View file

@ -379,7 +379,6 @@
D58E1C8628A2B0DE00AB683E /* Wifi View */ = {
isa = PBXGroup;
children = (
D567E2DD28C8D3E20009F768 /* SettingsView */,
D58E1C8728A2B10B00AB683E /* WifiView.swift */,
D567E2B728C137880009F768 /* WifiCell.swift */,
D51D1412293A53BD0028AEDD /* WifiCellViewModel.swift */,
@ -412,6 +411,7 @@
D59DFDB2268CCEAC001737F6 /* Views */ = {
isa = PBXGroup;
children = (
D567E2DD28C8D3E20009F768 /* SettingsView */,
D58E1C8628A2B0DE00AB683E /* Wifi View */,
D5507ACE26C668BC00512BAA /* UI Components */,
D59DFDB3268CCEB9001737F6 /* Onboarding Views */,

View file

@ -26,7 +26,7 @@ class NetworkService: ObservableObject {
// Session Configuration & Caching Policy
let configuration = URLSessionConfiguration.default
configuration.requestCachePolicy = .returnCacheDataElseLoad
// configuration.requestCachePolicy = .useProtocolCachePolicy
return URLSession(configuration: configuration)
}()
@ -34,8 +34,8 @@ class NetworkService: ObservableObject {
func fetch(completion: @escaping() -> Void) {
print("Attempting Network Request")
let request = URLRequest(url: URL(string: AdafruitInfo.baseURL)!, cachePolicy: URLRequest.CachePolicy.returnCacheDataElseLoad, timeoutInterval: 60.0)
let task = session.dataTask(with: request) { data, response, error in
let request = URLRequest(url: URL(string: AdafruitInfo.baseURL)!, cachePolicy: URLRequest.CachePolicy.reloadIgnoringLocalCacheData, timeoutInterval: 60.0)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("error: \(error)")

View file

@ -17,7 +17,7 @@ struct RunItButton: View {
.cornerRadius(25)
.foregroundColor(Color("pyleap_pink"))
Text("Run")
Text("Run it!")
.font(Font.custom("ReadexPro-Regular", size: 25))
.foregroundColor(Color.white)
.frame(height: 50)

View file

@ -7,49 +7,10 @@
import Foundation
import SwiftUI
import Network
import Combine
class InternetConnectionManager: ObservableObject {
private let monitor = NWPathMonitor()
private let queue = DispatchQueue(label: "InternetConnectionMonitor")
@Published var isConnected = false
init() {
startMonitoring(completion: {
monitor.pathUpdateHandler = { path in
DispatchQueue.main.async {
let newIsConnected = path.status == .satisfied
if self.isConnected != newIsConnected {
self.isConnected = newIsConnected
print("net: \(path.status) \(self.isConnected)")
}
}
}
})
}
func startMonitoring(completion:()->Void) {
print("Start Monitoring Network")
monitor.start(queue: queue)
completion()
}
deinit {
print("Network Deinit")
monitor.cancel()
}
}
class MainSelectionViewModel: ObservableObject {
@ObservedObject var networkModel = NetworkService()
@ObservedObject var networkMonitor = InternetConnectionManager()
let fileManager = FileManager.default
@ -58,30 +19,23 @@ class MainSelectionViewModel: ObservableObject {
let dataStore = DataStore()
@Published var pdemos : [ResultItem] = []
var networkMonitorCancellable: AnyCancellable?
init() {
let fileURL = documentsDirectory.appendingPathComponent("StandardPyLeapProjects.json")
networkMonitorCancellable = networkMonitor.$isConnected.sink { isConnected in
if isConnected {
print("The device is currently connected to the internet.")
// Perform some action when the device is connected to the internet.
self.networkModel.fetch {
self.pdemos = self.dataStore.loadDefaultList()
}
} else {
print("The device is not currently connected to the internet.")
// Perform some action when the device is not connected to the internet.
if fileManager.fileExists(atPath: fileURL.relativePath) {
print("Loading cached remote data.")
self.pdemos = self.dataStore.loadDefaultList()
} else {
print("Cached data not found. Fetching default list.")
networkModel.fetch {
self.pdemos = self.dataStore.loadDefaultList()
}
}
}