Compare commits
No commits in common. "master" and "Bug-WebView-Fix" have entirely different histories.
master
...
Bug-WebVie
10 changed files with 19 additions and 90 deletions
25
LICENSE.txt
25
LICENSE.txt
|
|
@ -1,25 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
|
|
||||||
Copyright (c) 2023 Adafruit Industries
|
|
||||||
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
@ -379,7 +379,6 @@
|
||||||
D58E1C8628A2B0DE00AB683E /* Wifi View */ = {
|
D58E1C8628A2B0DE00AB683E /* Wifi View */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
D567E2DD28C8D3E20009F768 /* SettingsView */,
|
|
||||||
D58E1C8728A2B10B00AB683E /* WifiView.swift */,
|
D58E1C8728A2B10B00AB683E /* WifiView.swift */,
|
||||||
D567E2B728C137880009F768 /* WifiCell.swift */,
|
D567E2B728C137880009F768 /* WifiCell.swift */,
|
||||||
D51D1412293A53BD0028AEDD /* WifiCellViewModel.swift */,
|
D51D1412293A53BD0028AEDD /* WifiCellViewModel.swift */,
|
||||||
|
|
@ -412,6 +411,7 @@
|
||||||
D59DFDB2268CCEAC001737F6 /* Views */ = {
|
D59DFDB2268CCEAC001737F6 /* Views */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
D567E2DD28C8D3E20009F768 /* SettingsView */,
|
||||||
D58E1C8628A2B0DE00AB683E /* Wifi View */,
|
D58E1C8628A2B0DE00AB683E /* Wifi View */,
|
||||||
D5507ACE26C668BC00512BAA /* UI Components */,
|
D5507ACE26C668BC00512BAA /* UI Components */,
|
||||||
D59DFDB3268CCEB9001737F6 /* Onboarding Views */,
|
D59DFDB3268CCEB9001737F6 /* Onboarding Views */,
|
||||||
|
|
@ -886,7 +886,7 @@
|
||||||
DEVELOPMENT_TEAM = 2X94RM7457;
|
DEVELOPMENT_TEAM = 2X94RM7457;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
INFOPLIST_FILE = PyLeap/Info.plist;
|
INFOPLIST_FILE = PyLeap/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
|
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
|
|
@ -916,7 +916,7 @@
|
||||||
DEVELOPMENT_TEAM = 2X94RM7457;
|
DEVELOPMENT_TEAM = 2X94RM7457;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
INFOPLIST_FILE = PyLeap/Info.plist;
|
INFOPLIST_FILE = PyLeap/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
|
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -26,7 +26,7 @@ class NetworkService: ObservableObject {
|
||||||
|
|
||||||
// Session Configuration & Caching Policy
|
// Session Configuration & Caching Policy
|
||||||
let configuration = URLSessionConfiguration.default
|
let configuration = URLSessionConfiguration.default
|
||||||
configuration.requestCachePolicy = .returnCacheDataElseLoad
|
// configuration.requestCachePolicy = .useProtocolCachePolicy
|
||||||
|
|
||||||
return URLSession(configuration: configuration)
|
return URLSession(configuration: configuration)
|
||||||
}()
|
}()
|
||||||
|
|
@ -34,8 +34,8 @@ class NetworkService: ObservableObject {
|
||||||
|
|
||||||
func fetch(completion: @escaping() -> Void) {
|
func fetch(completion: @escaping() -> Void) {
|
||||||
print("Attempting Network Request")
|
print("Attempting Network Request")
|
||||||
let request = URLRequest(url: URL(string: AdafruitInfo.baseURL)!, cachePolicy: URLRequest.CachePolicy.returnCacheDataElseLoad, timeoutInterval: 60.0)
|
let request = URLRequest(url: URL(string: AdafruitInfo.baseURL)!, cachePolicy: URLRequest.CachePolicy.reloadIgnoringLocalCacheData, timeoutInterval: 60.0)
|
||||||
let task = session.dataTask(with: request) { data, response, error in
|
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||||
|
|
||||||
if let error = error {
|
if let error = error {
|
||||||
print("error: \(error)")
|
print("error: \(error)")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ struct RunItButton: View {
|
||||||
.cornerRadius(25)
|
.cornerRadius(25)
|
||||||
.foregroundColor(Color("pyleap_pink"))
|
.foregroundColor(Color("pyleap_pink"))
|
||||||
|
|
||||||
Text("Run")
|
Text("Run it!")
|
||||||
.font(Font.custom("ReadexPro-Regular", size: 25))
|
.font(Font.custom("ReadexPro-Regular", size: 25))
|
||||||
.foregroundColor(Color.white)
|
.foregroundColor(Color.white)
|
||||||
.frame(height: 50)
|
.frame(height: 50)
|
||||||
|
|
|
||||||
|
|
@ -7,49 +7,10 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftUI
|
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 {
|
class MainSelectionViewModel: ObservableObject {
|
||||||
|
|
||||||
@ObservedObject var networkModel = NetworkService()
|
@ObservedObject var networkModel = NetworkService()
|
||||||
@ObservedObject var networkMonitor = InternetConnectionManager()
|
|
||||||
|
|
||||||
|
|
||||||
let fileManager = FileManager.default
|
let fileManager = FileManager.default
|
||||||
|
|
||||||
|
|
@ -58,30 +19,23 @@ class MainSelectionViewModel: ObservableObject {
|
||||||
let dataStore = DataStore()
|
let dataStore = DataStore()
|
||||||
|
|
||||||
@Published var pdemos : [ResultItem] = []
|
@Published var pdemos : [ResultItem] = []
|
||||||
var networkMonitorCancellable: AnyCancellable?
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
let fileURL = documentsDirectory.appendingPathComponent("StandardPyLeapProjects.json")
|
let fileURL = documentsDirectory.appendingPathComponent("StandardPyLeapProjects.json")
|
||||||
|
|
||||||
|
if fileManager.fileExists(atPath: fileURL.relativePath) {
|
||||||
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.
|
|
||||||
print("Loading cached remote data.")
|
print("Loading cached remote data.")
|
||||||
self.pdemos = self.dataStore.loadDefaultList()
|
self.pdemos = self.dataStore.loadDefaultList()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
print("Cached data not found. Fetching default list.")
|
||||||
|
networkModel.fetch {
|
||||||
|
self.pdemos = self.dataStore.loadDefaultList()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue