Constructed Wifi Web workflow view
This commit is contained in:
parent
2699629e2a
commit
d339f70bae
10 changed files with 883 additions and 186 deletions
|
|
@ -36,6 +36,9 @@
|
||||||
D5597C3B26B98E1E00DF17C0 /* NumbersOnly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5597C3A26B98E1E00DF17C0 /* NumbersOnly.swift */; };
|
D5597C3B26B98E1E00DF17C0 /* NumbersOnly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5597C3A26B98E1E00DF17C0 /* NumbersOnly.swift */; };
|
||||||
D5640216271B54BF00AE1519 /* MainSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5640215271B54BF00AE1519 /* MainSelectionView.swift */; };
|
D5640216271B54BF00AE1519 /* MainSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5640215271B54BF00AE1519 /* MainSelectionView.swift */; };
|
||||||
D567E2B628B81B730009F768 /* Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D567E2B528B81B730009F768 /* Queue.swift */; };
|
D567E2B628B81B730009F768 /* Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D567E2B528B81B730009F768 /* Queue.swift */; };
|
||||||
|
D567E2B828C137880009F768 /* WifiCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D567E2B728C137880009F768 /* WifiCell.swift */; };
|
||||||
|
D567E2BA28C1382E0009F768 /* WifiSubViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D567E2B928C1382E0009F768 /* WifiSubViewCell.swift */; };
|
||||||
|
D567E2BC28C1527F0009F768 /* WifiSubViewCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D567E2BB28C1527F0009F768 /* WifiSubViewCellModel.swift */; };
|
||||||
D56F640C270242CA000E5975 /* UIColor+LightAndDark.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F6407270242CA000E5975 /* UIColor+LightAndDark.swift */; };
|
D56F640C270242CA000E5975 /* UIColor+LightAndDark.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F6407270242CA000E5975 /* UIColor+LightAndDark.swift */; };
|
||||||
D56F640D270242CA000E5975 /* FileTransferPathUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F640A270242CA000E5975 /* FileTransferPathUtils.swift */; };
|
D56F640D270242CA000E5975 /* FileTransferPathUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F640A270242CA000E5975 /* FileTransferPathUtils.swift */; };
|
||||||
D56F640E270242CA000E5975 /* String+DeletingPrefix.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F6408270242CA000E5975 /* String+DeletingPrefix.swift */; };
|
D56F640E270242CA000E5975 /* String+DeletingPrefix.swift in Sources */ = {isa = PBXBuildFile; fileRef = D56F6408270242CA000E5975 /* String+DeletingPrefix.swift */; };
|
||||||
|
|
@ -119,6 +122,9 @@
|
||||||
D5640215271B54BF00AE1519 /* MainSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainSelectionView.swift; sourceTree = "<group>"; };
|
D5640215271B54BF00AE1519 /* MainSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainSelectionView.swift; sourceTree = "<group>"; };
|
||||||
D567E2B428B80DC10009F768 /* Outline.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Outline.md; sourceTree = "<group>"; };
|
D567E2B428B80DC10009F768 /* Outline.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Outline.md; sourceTree = "<group>"; };
|
||||||
D567E2B528B81B730009F768 /* Queue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Queue.swift; sourceTree = "<group>"; };
|
D567E2B528B81B730009F768 /* Queue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Queue.swift; sourceTree = "<group>"; };
|
||||||
|
D567E2B728C137880009F768 /* WifiCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WifiCell.swift; sourceTree = "<group>"; };
|
||||||
|
D567E2B928C1382E0009F768 /* WifiSubViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WifiSubViewCell.swift; sourceTree = "<group>"; };
|
||||||
|
D567E2BB28C1527F0009F768 /* WifiSubViewCellModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WifiSubViewCellModel.swift; sourceTree = "<group>"; };
|
||||||
D56F6407270242CA000E5975 /* UIColor+LightAndDark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+LightAndDark.swift"; sourceTree = "<group>"; };
|
D56F6407270242CA000E5975 /* UIColor+LightAndDark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+LightAndDark.swift"; sourceTree = "<group>"; };
|
||||||
D56F6408270242CA000E5975 /* String+DeletingPrefix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+DeletingPrefix.swift"; sourceTree = "<group>"; };
|
D56F6408270242CA000E5975 /* String+DeletingPrefix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+DeletingPrefix.swift"; sourceTree = "<group>"; };
|
||||||
D56F640A270242CA000E5975 /* FileTransferPathUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTransferPathUtils.swift; sourceTree = "<group>"; };
|
D56F640A270242CA000E5975 /* FileTransferPathUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTransferPathUtils.swift; sourceTree = "<group>"; };
|
||||||
|
|
@ -308,6 +314,9 @@
|
||||||
children = (
|
children = (
|
||||||
D58E1C8728A2B10B00AB683E /* WifiView.swift */,
|
D58E1C8728A2B10B00AB683E /* WifiView.swift */,
|
||||||
D58E1C8928A2B15E00AB683E /* WifiViewModel.swift */,
|
D58E1C8928A2B15E00AB683E /* WifiViewModel.swift */,
|
||||||
|
D567E2B728C137880009F768 /* WifiCell.swift */,
|
||||||
|
D567E2B928C1382E0009F768 /* WifiSubViewCell.swift */,
|
||||||
|
D567E2BB28C1527F0009F768 /* WifiSubViewCellModel.swift */,
|
||||||
D567E2B528B81B730009F768 /* Queue.swift */,
|
D567E2B528B81B730009F768 /* Queue.swift */,
|
||||||
D5BA1F7928B52A490012FC62 /* WifiListDetailView.swift */,
|
D5BA1F7928B52A490012FC62 /* WifiListDetailView.swift */,
|
||||||
D5BA1F7E28B66F280012FC62 /* Bonjour.swift */,
|
D5BA1F7E28B66F280012FC62 /* Bonjour.swift */,
|
||||||
|
|
@ -608,6 +617,7 @@
|
||||||
D5BA1F8328B68ED40012FC62 /* NetworkPeripheral.swift in Sources */,
|
D5BA1F8328B68ED40012FC62 /* NetworkPeripheral.swift in Sources */,
|
||||||
D59DFDBC268CE0EB001737F6 /* RootView.swift in Sources */,
|
D59DFDBC268CE0EB001737F6 /* RootView.swift in Sources */,
|
||||||
D595FC2E2812C23D00569D8C /* Image Extension.swift in Sources */,
|
D595FC2E2812C23D00569D8C /* Image Extension.swift in Sources */,
|
||||||
|
D567E2BA28C1382E0009F768 /* WifiSubViewCell.swift in Sources */,
|
||||||
D59DFD8F268A4A4D001737F6 /* BTConnectionView.swift in Sources */,
|
D59DFD8F268A4A4D001737F6 /* BTConnectionView.swift in Sources */,
|
||||||
D58D887B26CC02B60085604A /* OnboardingViewPure.swift in Sources */,
|
D58D887B26CC02B60085604A /* OnboardingViewPure.swift in Sources */,
|
||||||
D52BE85426A0E39100630900 /* BTConnectionViewModel.swift in Sources */,
|
D52BE85426A0E39100630900 /* BTConnectionViewModel.swift in Sources */,
|
||||||
|
|
@ -617,9 +627,11 @@
|
||||||
D5507AD126C668BC00512BAA /* SearchBarView.swift in Sources */,
|
D5507AD126C668BC00512BAA /* SearchBarView.swift in Sources */,
|
||||||
D59DFDBA268CDEEC001737F6 /* RootViewModel.swift in Sources */,
|
D59DFDBA268CDEEC001737F6 /* RootViewModel.swift in Sources */,
|
||||||
D5C74DF527EB93E300730505 /* DemoViewCell.swift in Sources */,
|
D5C74DF527EB93E300730505 /* DemoViewCell.swift in Sources */,
|
||||||
|
D567E2BC28C1527F0009F768 /* WifiSubViewCellModel.swift in Sources */,
|
||||||
D52BE85526A0E5A400630900 /* PeripheralList.swift in Sources */,
|
D52BE85526A0E5A400630900 /* PeripheralList.swift in Sources */,
|
||||||
D5D7DF2D28B489C0008552D1 /* WebDirectoryModel.swift in Sources */,
|
D5D7DF2D28B489C0008552D1 /* WebDirectoryModel.swift in Sources */,
|
||||||
D5597C0226ADDCE300DF17C0 /* StartupView.swift in Sources */,
|
D5597C0226ADDCE300DF17C0 /* StartupView.swift in Sources */,
|
||||||
|
D567E2B828C137880009F768 /* WifiCell.swift in Sources */,
|
||||||
D5D1F4B027ECFDE00040E2BF /* NavBarModifier.swift in Sources */,
|
D5D1F4B027ECFDE00040E2BF /* NavBarModifier.swift in Sources */,
|
||||||
D5597C0C26AF018800DF17C0 /* View+If.swift in Sources */,
|
D5597C0C26AF018800DF17C0 /* View+If.swift in Sources */,
|
||||||
D58E1C8D28A2B32C00AB683E /* Wifi_ifaddrs.m in Sources */,
|
D58E1C8D28A2B32C00AB683E /* Wifi_ifaddrs.m in Sources */,
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -191,7 +191,7 @@ class DownloadViewModel: NSObject, ObservableObject, URLSessionDownloadDelegate
|
||||||
// Since URL Session will be running in the background thread
|
// Since URL Session will be running in the background thread
|
||||||
// UI will be done on the main thread
|
// UI will be done on the main thread
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
self.downloadProgress = numeralProgress
|
self.downloadProgress = numeralProgress
|
||||||
print("Recorded downloadProgress Progress: \(self.downloadProgress)")
|
print("Recorded downloadProgress Progress: \(self.downloadProgress)")
|
||||||
print("Recorded numeralProgress Progress: \(numeralProgress)")
|
print("Recorded numeralProgress Progress: \(numeralProgress)")
|
||||||
|
|
|
||||||
|
|
@ -202,8 +202,13 @@ struct SelectionView: View {
|
||||||
SubHeaderView()
|
SubHeaderView()
|
||||||
// .spotlight(enabled: spotlight.counter == 1, title: "1")
|
// .spotlight(enabled: spotlight.counter == 1, title: "1")
|
||||||
|
|
||||||
|
let check = model.pdemos.filter {
|
||||||
|
$0.compatibility[0] == boardBootInfo
|
||||||
|
}
|
||||||
|
|
||||||
ForEach(model.pdemos) { demo in
|
ForEach(model.pdemos) { demo in
|
||||||
|
|
||||||
|
|
||||||
DemoViewCell(result: demo, isConnected: $inConnectedInSelectionView, bootOne: $boardBootInfo, onViewGeometryChanged: {
|
DemoViewCell(result: demo, isConnected: $inConnectedInSelectionView, bootOne: $boardBootInfo, onViewGeometryChanged: {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
scroll.scrollTo(demo.id)
|
scroll.scrollTo(demo.id)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ struct SubHeaderView: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
|
|
||||||
Text("Browse all of the available PyLeap Projects")
|
Text("Browse available Wi-Fi PyLeap Projects")
|
||||||
.multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
.multilineTextAlignment(/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
||||||
.font(Font.custom("ReadexPro-Regular", size: 25))
|
.font(Font.custom("ReadexPro-Regular", size: 25))
|
||||||
|
|
||||||
|
|
|
||||||
77
PyLeap/Views/Wifi_test/WifiCell.swift
Normal file
77
PyLeap/Views/Wifi_test/WifiCell.swift
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
//
|
||||||
|
// WifiCell.swift
|
||||||
|
// PyLeap
|
||||||
|
//
|
||||||
|
// Created by Trevor Beaton on 9/1/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct WifiCell: View {
|
||||||
|
|
||||||
|
let result : ResultItem
|
||||||
|
|
||||||
|
@State private var isExpanded: Bool = false {
|
||||||
|
didSet {
|
||||||
|
onViewGeometryChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Binding var isConnected: Bool
|
||||||
|
@Binding var bootOne: String
|
||||||
|
|
||||||
|
let onViewGeometryChanged: ()->Void
|
||||||
|
|
||||||
|
@Binding var stateBinder: DownloadState
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
content
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var content: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
|
header
|
||||||
|
|
||||||
|
if isExpanded {
|
||||||
|
|
||||||
|
Group {
|
||||||
|
WifiSubViewCell(bindingString: $bootOne, downloadStateBinder: $stateBinder, title: result.projectName,
|
||||||
|
image: result.projectImage,
|
||||||
|
description: result.description,
|
||||||
|
learnGuideLink: URLRequest(url: URL(string: result.learnGuideLink)!),
|
||||||
|
downloadLink: result.bundleLink,
|
||||||
|
compatibility: result.compatibility,
|
||||||
|
isConnected: $isConnected)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var header: some View {
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Text(result.projectName)
|
||||||
|
.font(Font.custom("ReadexPro-Regular", size: 24))
|
||||||
|
.padding(8)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Image(systemName: "chevron.down")
|
||||||
|
.resizable()
|
||||||
|
.frame(width: 30, height: 15, alignment: .center)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.padding(.trailing, 30)
|
||||||
|
}
|
||||||
|
|
||||||
|
.padding(.vertical, 5)
|
||||||
|
.padding(.leading)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.background(Color("pyleap_purple"))
|
||||||
|
.onTapGesture { isExpanded.toggle() }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
314
PyLeap/Views/Wifi_test/WifiSubViewCell.swift
Normal file
314
PyLeap/Views/Wifi_test/WifiSubViewCell.swift
Normal file
|
|
@ -0,0 +1,314 @@
|
||||||
|
//
|
||||||
|
// WifiSubViewCell.swift
|
||||||
|
// PyLeap
|
||||||
|
//
|
||||||
|
// Created by Trevor Beaton on 9/1/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import FileTransferClient
|
||||||
|
|
||||||
|
struct WifiSubViewCell: View {
|
||||||
|
@State var transferInProgress = false
|
||||||
|
@State var isDownloaded = false
|
||||||
|
|
||||||
|
@EnvironmentObject var globalString : GlobalString
|
||||||
|
|
||||||
|
@StateObject var viewModel = WifiViewModel()
|
||||||
|
|
||||||
|
@Binding var bindingString: String
|
||||||
|
|
||||||
|
@Binding var downloadStateBinder: DownloadState
|
||||||
|
|
||||||
|
@State private var toggleView: Bool = false
|
||||||
|
|
||||||
|
let title: String
|
||||||
|
let image: String
|
||||||
|
let description: String
|
||||||
|
let learnGuideLink: URLRequest
|
||||||
|
let downloadLink: String
|
||||||
|
let compatibility: [String]
|
||||||
|
|
||||||
|
@EnvironmentObject var rootViewModel: RootViewModel
|
||||||
|
@StateObject var downloadModel = DownloadViewModel()
|
||||||
|
|
||||||
|
@Binding var isConnected : Bool
|
||||||
|
|
||||||
|
@State private var showWebViewPopover: Bool = false
|
||||||
|
@State var errorOccured = false
|
||||||
|
@State private var presentAlert = false
|
||||||
|
|
||||||
|
@State var offlineWithoutProject = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
|
||||||
|
VStack {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 0, content: {
|
||||||
|
|
||||||
|
ImageWithURL(image)
|
||||||
|
.scaledToFit()
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.cornerRadius(14)
|
||||||
|
.padding(.top, 30)
|
||||||
|
|
||||||
|
|
||||||
|
Text(description)
|
||||||
|
.font(Font.custom("ReadexPro-Regular", size: 18))
|
||||||
|
.multilineTextAlignment(.leading)
|
||||||
|
.minimumScaleFactor(0.1)
|
||||||
|
.padding(.top, 20)
|
||||||
|
Text("Compatible with:")
|
||||||
|
.font(Font.custom("ReadexPro-Bold", size: 18))
|
||||||
|
.padding(.top, 5)
|
||||||
|
|
||||||
|
|
||||||
|
ForEach(compatibility, id: \.self) { string in
|
||||||
|
if string == "circuitplayground_bluefruit" {
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "checkmark")
|
||||||
|
.resizable()
|
||||||
|
.frame(width: 25, height: 22, alignment: .center)
|
||||||
|
.foregroundColor(.green)
|
||||||
|
Text("Circuit Playground Bluefruit")
|
||||||
|
.font(Font.custom("ReadexPro-Regular", size: 18))
|
||||||
|
.foregroundColor(.black)
|
||||||
|
}
|
||||||
|
.padding(.top, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if string == "clue_nrf52840_express" {
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "checkmark")
|
||||||
|
.resizable()
|
||||||
|
.frame(width: 25, height: 22, alignment: .center)
|
||||||
|
.foregroundColor(.green)
|
||||||
|
Text("Adafruit CLUE")
|
||||||
|
.font(Font.custom("ReadexPro-Regular", size: 18))
|
||||||
|
.foregroundColor(.black)
|
||||||
|
}
|
||||||
|
.padding(.top, 10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ignoresSafeArea(.all)
|
||||||
|
.padding(.horizontal, 30)
|
||||||
|
|
||||||
|
Button(action: {
|
||||||
|
showWebViewPopover = true
|
||||||
|
|
||||||
|
}) {
|
||||||
|
LearnGuideButton()
|
||||||
|
.padding(.top, 20)
|
||||||
|
}
|
||||||
|
.sheet(isPresented: $showWebViewPopover, content: {
|
||||||
|
WebView(URLRequest(url: learnGuideLink.url!))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if isConnected {
|
||||||
|
|
||||||
|
if compatibility.contains(bindingString) {
|
||||||
|
|
||||||
|
Button {
|
||||||
|
print("Wifi Project Attempt \(title)")
|
||||||
|
|
||||||
|
if viewModel.projectDownloaded {
|
||||||
|
viewModel.projectValidation(nameOf: title)
|
||||||
|
} else {
|
||||||
|
downloadModel.startDownload(urlString: downloadLink, projectTitle: title) {
|
||||||
|
print("DONE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//viewModel.projectValidation(nameOf: title)
|
||||||
|
} label: {
|
||||||
|
RunItButton()
|
||||||
|
.padding(.top, 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if downloadStateBinder == .idle {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Button(action: {
|
||||||
|
//
|
||||||
|
// downloadStateBinder = .transferring
|
||||||
|
// globalString.isSendingG = true
|
||||||
|
// globalString.counterG = 0
|
||||||
|
// globalString.numberOfFilesG = 1
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// globalString.downloadLinkString = downloadLink
|
||||||
|
// globalString.projectString = title
|
||||||
|
// globalString.attemptToDownload.toggle()
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if selectionModel.isConnectedToInternet == false {
|
||||||
|
// print("Going offline...")
|
||||||
|
// downloadStateBinder = .transferring
|
||||||
|
//
|
||||||
|
// globalString.projectString = title
|
||||||
|
// globalString.attemptToSend.toggle()
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if viewModel.projectDownloaded == false && selectionModel.isConnectedToInternet == false {
|
||||||
|
// offlineWithoutProject = true
|
||||||
|
// downloadStateBinder = .idle
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if viewModel.projectDownloaded == false {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }) {
|
||||||
|
//
|
||||||
|
// RunItButton()
|
||||||
|
// .padding(.top, 20)
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if downloadStateBinder == .failed {
|
||||||
|
//
|
||||||
|
// FailedButton()
|
||||||
|
// .padding(.top, 20)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if downloadStateBinder == .transferring {
|
||||||
|
//
|
||||||
|
// Button(action: {
|
||||||
|
//
|
||||||
|
// print("Project Selected: \(title) - DemoSubView")
|
||||||
|
//
|
||||||
|
// globalString.projectString = title
|
||||||
|
// globalString.numberOfTimesDownloaded += 1
|
||||||
|
//
|
||||||
|
// }) {
|
||||||
|
//
|
||||||
|
// DownloadingButton()
|
||||||
|
// .padding(.top, 20)
|
||||||
|
// }
|
||||||
|
// .disabled(true)
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if globalString.isSendingG {
|
||||||
|
//
|
||||||
|
// VStack(alignment: .center, spacing: 0) {
|
||||||
|
// ProgressView("", value: CGFloat(globalString.counterG), total: CGFloat(globalString.numberOfFilesG) )
|
||||||
|
// .padding(.horizontal, 90)
|
||||||
|
// .padding(.top, -8)
|
||||||
|
// .padding(.bottom, 10)
|
||||||
|
// .accentColor(Color.gray)
|
||||||
|
// .scaleEffect(x: 1, y: 2, anchor: .center)
|
||||||
|
// .cornerRadius(10)
|
||||||
|
// .frame(height: 10)
|
||||||
|
//
|
||||||
|
// ProgressView()
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if downloadStateBinder == .complete {
|
||||||
|
//
|
||||||
|
// CompleteButton()
|
||||||
|
// .padding(.top, 20)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Button {
|
||||||
|
rootViewModel.goTobluetoothPairing()
|
||||||
|
} label: {
|
||||||
|
ConnectButton()
|
||||||
|
.padding(.top, 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
.frame(height: 30)
|
||||||
|
.ignoresSafeArea(.all)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.alert("Project Not Found", isPresented: $offlineWithoutProject) {
|
||||||
|
Button("OK") {
|
||||||
|
// Handle acknowledgement.
|
||||||
|
print("OK")
|
||||||
|
offlineWithoutProject = false
|
||||||
|
downloadStateBinder = .idle
|
||||||
|
// selectionModel.state = .idle
|
||||||
|
print("\(offlineWithoutProject)")
|
||||||
|
}
|
||||||
|
} message: {
|
||||||
|
Text("""
|
||||||
|
To use this project, connect to the internet.
|
||||||
|
""")
|
||||||
|
.multilineTextAlignment(.leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
.onChange(of: downloadModel.isDownloading, perform: { newValue in
|
||||||
|
viewModel.getProjectForSubClass(nameOf: title)
|
||||||
|
})
|
||||||
|
|
||||||
|
.onChange(of: downloadModel.didDownloadBundle, perform: { newValue in
|
||||||
|
print("For project: \(title), project download is \(newValue)")
|
||||||
|
|
||||||
|
// globalString.projectString = title
|
||||||
|
|
||||||
|
if newValue {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
print("Getting project from Subclass \(title)")
|
||||||
|
// viewModel.getProjectForSubClass(nameOf: title)
|
||||||
|
viewModel.projectValidation(nameOf: title)
|
||||||
|
|
||||||
|
isDownloaded = true
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
print("Is not downloaded")
|
||||||
|
isDownloaded = false
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.onAppear(perform: {
|
||||||
|
viewModel.getProjectForSubClass(nameOf: title)
|
||||||
|
if viewModel.projectDownloaded {
|
||||||
|
isDownloaded = true
|
||||||
|
} else {
|
||||||
|
isDownloaded = false
|
||||||
|
}
|
||||||
|
print("is downloaded? \(isDownloaded)")
|
||||||
|
})
|
||||||
|
.padding(.top, 8)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
47
PyLeap/Views/Wifi_test/WifiSubViewCellModel.swift
Normal file
47
PyLeap/Views/Wifi_test/WifiSubViewCellModel.swift
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// WifiSubViewCellModel.swift
|
||||||
|
// PyLeap
|
||||||
|
//
|
||||||
|
// Created by Trevor Beaton on 9/1/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class WifiSubViewCellModel: ObservableObject {
|
||||||
|
|
||||||
|
@Published var projectDownloaded = false
|
||||||
|
@Published var failedProjectLaunch = false
|
||||||
|
|
||||||
|
let directoryPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||||
|
|
||||||
|
func getProjectForSubClass(nameOf project: String) {
|
||||||
|
|
||||||
|
if let enumerator = FileManager.default.enumerator(at: directoryPath, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
|
||||||
|
// for case condition: Only process URLs
|
||||||
|
for case let fileURL as URL in enumerator {
|
||||||
|
|
||||||
|
if fileURL.lastPathComponent == project {
|
||||||
|
failedProjectLaunch = false
|
||||||
|
projectDownloaded = true
|
||||||
|
print(#function)
|
||||||
|
print("Searching for... \(project)")
|
||||||
|
print("URL Path: \(fileURL.path)")
|
||||||
|
print("URL : \(fileURL)")
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
} else {
|
||||||
|
failedProjectLaunch = true
|
||||||
|
projectDownloaded = false
|
||||||
|
print("Project was not found...")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,11 @@ import SwiftUI
|
||||||
|
|
||||||
struct WifiView: View {
|
struct WifiView: View {
|
||||||
@StateObject var viewModel = WifiViewModel()
|
@StateObject var viewModel = WifiViewModel()
|
||||||
|
@ObservedObject var networkModel = NetworkService()
|
||||||
|
@State private var downloadState = DownloadState.idle
|
||||||
|
@State private var scrollViewID = UUID()
|
||||||
|
@State private var inConnectedInWifiView = true
|
||||||
|
@State private var boardBootInfo = "esp32-s2"
|
||||||
|
|
||||||
@State private var ipAddressInput: String = ""
|
@State private var ipAddressInput: String = ""
|
||||||
@State private var foundIPAddress: String = ""
|
@State private var foundIPAddress: String = ""
|
||||||
|
|
@ -19,78 +24,132 @@ struct WifiView: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
|
|
||||||
VStack(alignment: .center, spacing: 12, content: {
|
VStack(alignment: .center, spacing: 0, content: {
|
||||||
|
HeaderView()
|
||||||
TextField("Enter your IP Address:", text: $ipAddressInput)
|
|
||||||
.frame(width: 200, height: 50, alignment: .center)
|
// HStack(alignment: .center, spacing: 8, content: {
|
||||||
|
//
|
||||||
|
// Button {
|
||||||
|
// // rootViewModel.goToWifiView()
|
||||||
|
// } label: {
|
||||||
|
// Text("Connect to Wifi")
|
||||||
|
// .font(Font.custom("ReadexPro-Regular", size: 16))
|
||||||
|
// .underline()
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// })
|
||||||
|
.padding(.all, 0.0)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.frame(maxHeight: 40)
|
||||||
|
.background(Color("pyleap_blue"))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
|
||||||
|
|
||||||
|
ScrollView(.vertical, showsIndicators: true) {
|
||||||
|
|
||||||
.foregroundColor(.black)
|
// TextField("Enter your IP Address:", text: $ipAddressInput)
|
||||||
|
// .frame(width: 200, height: 50, alignment: .center)
|
||||||
Button("Make Directory") {
|
//
|
||||||
// viewModel.putDirectory()
|
// .foregroundColor(.black)
|
||||||
}
|
//
|
||||||
|
// Button("Make Directory") {
|
||||||
Button("GET Request") {
|
// // viewModel.putDirectory()
|
||||||
viewModel.getRequest()
|
// }
|
||||||
}
|
//
|
||||||
|
// Button("GET Request") {
|
||||||
Button("PUT Request") {
|
// viewModel.getRequest()
|
||||||
viewModel.putRequest()
|
// }
|
||||||
}
|
//
|
||||||
|
// Button("PUT Request") {
|
||||||
Button("DELETE Request") { viewModel.deleteRequest() }
|
// viewModel.putRequest()
|
||||||
|
// }
|
||||||
Button("Single IP Addr.") { print(viewModel.wifiService.getIPAddress()) }
|
//
|
||||||
|
// Button("DELETE Request") { viewModel.deleteRequest() }
|
||||||
Button("IP Addr. List") { print(viewModel.wifiService.getIFAddresses()) }
|
//
|
||||||
|
// Button("Single IP Addr.") { print(viewModel.wifiService.getIPAddress()) }
|
||||||
Button("Get Project") {
|
//
|
||||||
viewModel.projectValidation(nameOf: "ESP32-S2 NeoPixel LED")
|
// Button("IP Addr. List") { print(viewModel.wifiService.getIFAddresses()) }
|
||||||
}
|
//
|
||||||
|
// Button("Get Project") {
|
||||||
|
//
|
||||||
ZStack {
|
//
|
||||||
Circle()
|
//
|
||||||
.foregroundColor(Color("pyleap_green"))
|
// // viewModel.projectValidation(nameOf: "Sensor Data Display")
|
||||||
.frame(width: 60, height: 60, alignment: .center)
|
// }
|
||||||
.opacity(0.8)
|
|
||||||
|
|
||||||
|
// ZStack {
|
||||||
|
// Circle()
|
||||||
|
// .foregroundColor(Color("pyleap_green"))
|
||||||
|
// .frame(width: 60, height: 60, alignment: .center)
|
||||||
|
// .opacity(0.8)
|
||||||
|
//
|
||||||
|
// Image(systemName: "checkmark")
|
||||||
|
// .resizable()
|
||||||
|
// .foregroundColor(.white)
|
||||||
|
// .frame(width: 30, height: 30, alignment: .center)
|
||||||
|
// }
|
||||||
|
// .isHidden(showConfirmation)
|
||||||
|
|
||||||
|
ScrollViewReader { scroll in
|
||||||
|
|
||||||
Image(systemName: "checkmark")
|
SubHeaderView()
|
||||||
.resizable()
|
// .spotlight(enabled: spotlight.counter == 1, title: "1")
|
||||||
.foregroundColor(.white)
|
|
||||||
.frame(width: 30, height: 30, alignment: .center)
|
let check = networkModel.pdemos.filter {
|
||||||
}
|
$0.compatibility[0] == boardBootInfo
|
||||||
.isHidden(showConfirmation)
|
}
|
||||||
|
|
||||||
List(viewModel.webDirectoryInfo) { post in
|
ForEach(check) { demo in
|
||||||
|
|
||||||
NavigationLink(destination: WifiListDetailView(text: post.name)) {
|
|
||||||
HStack(){
|
|
||||||
|
|
||||||
if post.directory == true {
|
|
||||||
Image(systemName: "folder")
|
|
||||||
} else {
|
|
||||||
Image(systemName: "doc")
|
|
||||||
}
|
|
||||||
|
|
||||||
Text(post.name)
|
WifiCell(result: demo, isConnected: $inConnectedInWifiView, bootOne: $boardBootInfo, onViewGeometryChanged: {
|
||||||
|
withAnimation {
|
||||||
Spacer()
|
scroll.scrollTo(demo.id)
|
||||||
|
}
|
||||||
if post.file_size > 1000 {
|
}, stateBinder: $downloadState)
|
||||||
|
|
||||||
Text("\(post.file_size/1000) KB")
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Text("\(post.file_size) Bytes")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.id(self.scrollViewID)
|
||||||
}
|
}
|
||||||
.frame(height: UIScreen.main.bounds.height/2)
|
.foregroundColor(.black)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// List(viewModel.webDirectoryInfo) { post in
|
||||||
|
//
|
||||||
|
// NavigationLink(destination: WifiListDetailView(text: post.name)) {
|
||||||
|
// HStack(){
|
||||||
|
//
|
||||||
|
// if post.directory == true {
|
||||||
|
// Image(systemName: "folder")
|
||||||
|
// } else {
|
||||||
|
// Image(systemName: "doc")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Text(post.name)
|
||||||
|
//
|
||||||
|
// Spacer()
|
||||||
|
//
|
||||||
|
// if post.file_size > 1000 {
|
||||||
|
//
|
||||||
|
// Text("\(post.file_size/1000) KB")
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// Text("\(post.file_size) Bytes")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
.frame(height: UIScreen.main.bounds.height)
|
||||||
})
|
})
|
||||||
|
|
||||||
// .navigationBarTitle(Text("PyLeap - Wi-Fi"))
|
// .navigationBarTitle(Text("PyLeap - Wi-Fi"))
|
||||||
|
|
|
||||||
|
|
@ -313,35 +313,95 @@ class WifiViewModel: ObservableObject {
|
||||||
print("Current projectDirectories: \(projectDirectories[0])")
|
print("Current projectDirectories: \(projectDirectories[0])")
|
||||||
|
|
||||||
|
|
||||||
// sortDirectory(directoryArray: projectDirectories, fileArray: fileURLs)
|
// sortDirectory(directoryArray: projectDirectories, fileArray: fileURLs)
|
||||||
pathManipulation(arrayOfAny: projectDirectories)
|
pathManipulation(arrayOfAny: filterOutCPDirectories(fileArray: projectDirectories), fileArray: fileURLs)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func intakeArray(path: URL) {
|
||||||
func pathManipulation(arrayOfAny: [URL]){
|
|
||||||
|
|
||||||
var indexOfCP = 0
|
var indexOfCP = 0
|
||||||
|
//path.pathComponents.removeSubrange(0...indexOfCP)
|
||||||
var tempPath = arrayOfAny.first
|
|
||||||
// tempPath?.pathComponents.firstIndex(of: "CircuitPython%208.x")
|
|
||||||
print("CircuitPython%207.x \(String(describing: tempPath?.pathComponents.firstIndex(of: "CircuitPython 7.x")))")
|
|
||||||
|
|
||||||
// indexOfCP = tempPath?.pathComponents.firstIndex(of: "CircuitPython 7.x")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortDirectory(directoryArray: [URL], fileArray: [URL]) {
|
func filterOutCPDirectories(fileArray: [URL]) -> [URL] {
|
||||||
|
|
||||||
|
let test = fileArray.filter {
|
||||||
|
$0.lastPathComponent != ("CircuitPython 8.x")
|
||||||
|
}
|
||||||
|
|
||||||
|
let test2 = test.filter {
|
||||||
|
$0.lastPathComponent != ("CircuitPython 7.x")
|
||||||
|
}
|
||||||
|
|
||||||
|
return test2
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func exit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var returnedArray = [[String]]()
|
||||||
|
|
||||||
|
func pathManipulation(arrayOfAny: [URL], fileArray: [URL]) {
|
||||||
print(#function)
|
print(#function)
|
||||||
|
var indexOfCP = 0
|
||||||
|
|
||||||
|
|
||||||
|
print("RETURNED PATHS: \(returnedArray)")
|
||||||
|
|
||||||
|
var tempArray = arrayOfAny
|
||||||
|
|
||||||
|
if arrayOfAny.isEmpty {
|
||||||
|
// Continue
|
||||||
|
print("Done!")
|
||||||
|
validateDirectory(directoryArray: returnedArray, fileArray: fileArray)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var tempPath = arrayOfAny[0].pathComponents
|
||||||
|
|
||||||
|
if arrayOfAny[0].pathComponents.contains("CircuitPython 7.x") {
|
||||||
|
print("Found CircuitPython 8.x")
|
||||||
|
|
||||||
|
indexOfCP = arrayOfAny[0].pathComponents.firstIndex(of: "CircuitPython 7.x")!
|
||||||
|
|
||||||
|
tempPath.removeSubrange(0...indexOfCP)
|
||||||
|
|
||||||
|
tempArray.removeFirst()
|
||||||
|
returnedArray.append(tempPath)
|
||||||
|
pathManipulation(arrayOfAny: tempArray, fileArray: fileArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
if arrayOfAny[0].pathComponents.contains("CircuitPython 8.x") {
|
||||||
|
print("Found CircuitPython 7.x")
|
||||||
|
indexOfCP = arrayOfAny[0].pathComponents.firstIndex(of: "CircuitPython 8.x")!
|
||||||
|
|
||||||
|
tempPath.removeSubrange(0...indexOfCP)
|
||||||
|
|
||||||
|
tempArray.removeFirst()
|
||||||
|
returnedArray.append(tempPath)
|
||||||
|
pathManipulation(arrayOfAny: tempArray, fileArray: fileArray)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var sortedDirectoryArray = directoryArray.sorted(by: { $1.pathComponents.count > $0.pathComponents.count} )
|
|
||||||
var sortedFileArray = fileArray.sorted(by: { $1.pathComponents.count > $0.pathComponents.count} )
|
|
||||||
validateDirectory(directoryArray: sortedDirectoryArray, fileArray: sortedFileArray)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDirectory(directoryArray: [URL], fileArray: [URL]) {
|
// func sortDirectory(directoryArray: [URL], fileArray: [URL]) {
|
||||||
|
// print(#function)
|
||||||
|
//
|
||||||
|
// var sortedDirectoryArray = directoryArray.sorted(by: { $1.pathComponents.count > $0.pathComponents.count} )
|
||||||
|
// var sortedFileArray = fileArray.sorted(by: { $1.pathComponents.count > $0.pathComponents.count} )
|
||||||
|
// validateDirectory(directoryArray: sortedDirectoryArray, fileArray: sortedFileArray)
|
||||||
|
// }
|
||||||
|
|
||||||
|
func validateDirectory(directoryArray: [[String]], fileArray: [URL]) {
|
||||||
print(#function)
|
print(#function)
|
||||||
// Use Recursion to go through each directory
|
// Use Recursion to go through each directory
|
||||||
if directoryArray.isEmpty {
|
if self.returnedArray.isEmpty {
|
||||||
print("No directories left in queue")
|
print("No directories left in queue")
|
||||||
print("Start file transfer...")
|
print("Start file transfer...")
|
||||||
// self.transferFiles(files: fileArray)
|
// self.transferFiles(files: fileArray)
|
||||||
|
|
@ -353,24 +413,21 @@ class WifiViewModel: ObservableObject {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Array count \(directoryArray.count)")
|
print("Array count \(returnedArray.count)")
|
||||||
|
|
||||||
makeDirectory(directoryArray: directoryArray, fileArray: fileArray, firstDirectory: firstDirectory)
|
makeDirectory(fileArray: fileArray)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeDirectory(directoryArray: [URL], fileArray: [URL], firstDirectory: URL) {
|
func makeDirectory(fileArray: [URL]) {
|
||||||
print(#function)
|
print(#function)
|
||||||
var temp = directoryArray
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var tempPath = firstDirectory.pathComponents
|
var tempPath = returnedArray[0]
|
||||||
tempPath.removeFirst(12)
|
|
||||||
print("Original Path: \(firstDirectory.absoluteURL)")
|
|
||||||
let joined = tempPath.joined(separator: "/")
|
let joined = tempPath.joined(separator: "/")
|
||||||
print("Outgoing path:\(joined)")
|
print("Outgoing path:\(joined)")
|
||||||
|
|
||||||
|
|
@ -380,8 +437,8 @@ class WifiViewModel: ObservableObject {
|
||||||
|
|
||||||
case .success(let consent):
|
case .success(let consent):
|
||||||
print("Successful")
|
print("Successful")
|
||||||
temp.removeFirst()
|
self.returnedArray.removeFirst()
|
||||||
self.validateDirectory(directoryArray: temp, fileArray: fileArray)
|
self.validateDirectory(directoryArray: self.returnedArray, fileArray: fileArray)
|
||||||
|
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
print("Error: \(error)")
|
print("Error: \(error)")
|
||||||
|
|
@ -391,101 +448,196 @@ class WifiViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFile(files: [URL]) {
|
func makeFile(files: [URL]) {
|
||||||
|
print(#function)
|
||||||
var copiedArray = files
|
var copiedArray = files
|
||||||
|
|
||||||
if files.isEmpty {
|
if files.isEmpty {
|
||||||
print("Transfer Complete")
|
print("Transfer Complete")
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
// let file = files[0].pathComponents.removeFirst(12) //this is the file. we will write to and read from it
|
// let file = files[0].pathComponents.removeFirst(12) //this is the file. we will write to and read from it
|
||||||
|
|
||||||
|
|
||||||
if copiedArray.first?.lastPathComponent == "README.txt" {
|
if copiedArray.first?.lastPathComponent == "README.txt" {
|
||||||
print("Removing README")
|
print("Removing README")
|
||||||
copiedArray.removeFirst()
|
copiedArray.removeFirst()
|
||||||
makeFile(files: copiedArray)
|
makeFile(files: copiedArray)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var tempURL = copiedArray[0].pathComponents
|
|
||||||
tempURL.removeFirst(12)
|
// print("copiedArray[0] \(copiedArray[0].pathComponents)")
|
||||||
let joined = tempURL.joined(separator: "/")
|
// var tempURL = copiedArray[0].pathComponents
|
||||||
print()
|
// tempURL.removeFirst(12)
|
||||||
|
// let joined = tempURL.joined(separator: "/")
|
||||||
var text = "some text" //just a text
|
// print("Joined \(joined)")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// var text = "some text" //just a text
|
||||||
|
|
||||||
guard let data = try? Data(contentsOf: URL(fileURLWithPath: copiedArray[0].path, relativeTo: copiedArray[0])) else {
|
guard let data = try? Data(contentsOf: URL(fileURLWithPath: copiedArray[0].path, relativeTo: copiedArray[0])) else {
|
||||||
print("File not found")
|
print("File not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var tempPath = copiedArray[0].pathComponents
|
||||||
|
print("PRINT INCOMING: \(tempPath)")
|
||||||
|
|
||||||
sendPutRequest(the: joined, to: copiedArray[0].absoluteURL, body: data) { result in
|
if copiedArray[0].pathComponents.contains("CircuitPython 7.x") {
|
||||||
switch result {
|
print("Found CircuitPython 7.x")
|
||||||
|
|
||||||
|
var indexOfCP = 0
|
||||||
|
|
||||||
|
indexOfCP = copiedArray[0].pathComponents.firstIndex(of: "CircuitPython 7.x")!
|
||||||
|
|
||||||
|
tempPath.removeSubrange(0...indexOfCP)
|
||||||
|
|
||||||
|
let joined = tempPath.joined(separator: "/")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (copiedArray[0].pathExtension == "py") || (copiedArray[0].pathExtension == "txt") {
|
||||||
|
|
||||||
case .success(_):
|
putRequest(fileName: joined, fileContent: data) { result in
|
||||||
print("Success")
|
switch result {
|
||||||
|
|
||||||
|
case .success(let content):
|
||||||
|
copiedArray.removeFirst()
|
||||||
|
self.makeFile(files: copiedArray)
|
||||||
|
case .failure(let error):
|
||||||
|
print("Failed write")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
sendPutRequest(fileName: joined, body: data) { result in
|
||||||
|
switch result {
|
||||||
|
|
||||||
|
case .success(_):
|
||||||
|
print("Success")
|
||||||
|
|
||||||
|
copiedArray.removeFirst()
|
||||||
|
self.makeFile(files: copiedArray)
|
||||||
|
case .failure(_):
|
||||||
|
print("Failed to write")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
copiedArray.removeFirst()
|
|
||||||
self.makeFile(files: copiedArray)
|
|
||||||
case .failure(_):
|
|
||||||
print("Failed to write")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// do {
|
if copiedArray[0].pathComponents.contains("CircuitPython 8.x") {
|
||||||
// let text2 = try String(contentsOf: copiedArray[10], encoding: .utf8)
|
print("Found CircuitPython 8.x")
|
||||||
// text = text2
|
var tempPath = copiedArray[0].pathComponents
|
||||||
//
|
|
||||||
//
|
var indexOfCP = Int()
|
||||||
//
|
|
||||||
//
|
indexOfCP = copiedArray[0].pathComponents.firstIndex(of: "CircuitPython 8.x")!
|
||||||
//// putRequest(fileName: joined, fileContent: data) { result in
|
|
||||||
//// switch result {
|
tempPath.removeSubrange(0...indexOfCP)
|
||||||
////
|
let joined = tempPath.joined(separator: "/")
|
||||||
//// case .success(let content):
|
print("joined : \(joined)")
|
||||||
//// copiedArray.removeFirst()
|
|
||||||
//// self.makeFile(files: copiedArray)
|
if (copiedArray[0].pathExtension == "py") || (copiedArray[0].pathExtension == "txt") {
|
||||||
//// case .failure(let error):
|
|
||||||
//// print("Failed write")
|
putRequest(fileName: joined, fileContent: data) { result in
|
||||||
//// }
|
switch result {
|
||||||
//// }
|
|
||||||
//
|
case .success(let content):
|
||||||
// } catch {
|
copiedArray.removeFirst()
|
||||||
// print("catch error")
|
self.makeFile(files: copiedArray)
|
||||||
// }
|
case .failure(let error):
|
||||||
|
print("Failed write")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
sendPutRequest(fileName: joined, body: data) { result in
|
||||||
|
switch result {
|
||||||
|
|
||||||
|
case .success(_):
|
||||||
|
print("Success")
|
||||||
|
|
||||||
|
copiedArray.removeFirst()
|
||||||
|
self.makeFile(files: copiedArray)
|
||||||
|
case .failure(_):
|
||||||
|
print("Failed to write")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// do {
|
||||||
|
// let text2 = try String(contentsOf: copiedArray[10], encoding: .utf8)
|
||||||
|
// text = text2
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// putRequest(fileName: joined, fileContent: data) { result in
|
||||||
|
//// switch result {
|
||||||
|
////
|
||||||
|
//// case .success(let content):
|
||||||
|
//// copiedArray.removeFirst()
|
||||||
|
//// self.makeFile(files: copiedArray)
|
||||||
|
//// case .failure(let error):
|
||||||
|
//// print("Failed write")
|
||||||
|
//// }
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
// } catch {
|
||||||
|
// print("catch error")
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// do {
|
||||||
|
// let text2 = try String(contentsOf: fileURLs[0], encoding: .utf8)
|
||||||
|
// text = text2
|
||||||
|
// putRequest(fileName: file, fileContent: text)
|
||||||
|
// }
|
||||||
|
// catch {/* error handling here */}
|
||||||
|
//
|
||||||
|
// print("Reading File:")
|
||||||
|
// print("""
|
||||||
|
//\(text)
|
||||||
|
//""")
|
||||||
|
|
||||||
//
|
|
||||||
// do {
|
|
||||||
// let text2 = try String(contentsOf: fileURLs[0], encoding: .utf8)
|
|
||||||
// text = text2
|
|
||||||
// putRequest(fileName: file, fileContent: text)
|
|
||||||
// }
|
|
||||||
// catch {/* error handling here */}
|
|
||||||
//
|
|
||||||
// print("Reading File:")
|
|
||||||
// print("""
|
|
||||||
//\(text)
|
|
||||||
//""")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// var tempURL = files[0].pathComponents
|
|
||||||
// tempURL.removeFirst(12)
|
|
||||||
// print(tempURL.joined(separator: "/"))
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var tempURL = files[0].pathComponents
|
||||||
|
// tempURL.removeFirst(12)
|
||||||
|
// print(tempURL.joined(separator: "/"))
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func sendPutRequest(the fileName: String, to url: URL,
|
|
||||||
|
func sendPutRequest(fileName: String,
|
||||||
body: Data,
|
body: Data,
|
||||||
then handler: @escaping(Result<Data, Error>) -> Void) {
|
then handler: @escaping(Result<Data, Error>) -> Void) {
|
||||||
|
|
||||||
|
|
@ -519,26 +671,26 @@ class WifiViewModel: ObservableObject {
|
||||||
print(request.cURL(pretty: true))
|
print(request.cURL(pretty: true))
|
||||||
|
|
||||||
let task = urlSession.dataTask(
|
let task = urlSession.dataTask(
|
||||||
with: request,
|
with: request,
|
||||||
completionHandler: { data, response, error in
|
completionHandler: { data, response, error in
|
||||||
// Validate response and call handler
|
// Validate response and call handler
|
||||||
|
|
||||||
if let error = error {
|
if let error = error {
|
||||||
print("File write error")
|
print("File write error")
|
||||||
|
|
||||||
handler(.failure(error))
|
handler(.failure(error))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let data = data {
|
if let data = data {
|
||||||
print("File write success!")
|
print("File write success!")
|
||||||
handler(.success(data))
|
handler(.success(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
task.resume()
|
task.resume()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -670,8 +822,8 @@ class WifiViewModel: ObservableObject {
|
||||||
semaphore.wait()
|
semaphore.wait()
|
||||||
return outgoingString
|
return outgoingString
|
||||||
}
|
}
|
||||||
// func putDirectory(directoryPath: String, completion: @escaping (Result<Data?, Error>) -> Void) {
|
// func putDirectory(directoryPath: String, completion: @escaping (Result<Data?, Error>) -> Void) {
|
||||||
|
|
||||||
func putRequest(fileName: String, fileContent: Data, completion: @escaping (Result<Data?, Error>) -> Void) {
|
func putRequest(fileName: String, fileContent: Data, completion: @escaping (Result<Data?, Error>) -> Void) {
|
||||||
print("Test Transfer")
|
print("Test Transfer")
|
||||||
let parameters = fileContent
|
let parameters = fileContent
|
||||||
|
|
@ -701,7 +853,7 @@ class WifiViewModel: ObservableObject {
|
||||||
let task = URLSession.shared.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("File write error")
|
print("File write error")
|
||||||
|
|
||||||
completion(.failure(error))
|
completion(.failure(error))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -711,7 +863,7 @@ class WifiViewModel: ObservableObject {
|
||||||
completion(.success(data))
|
completion(.success(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// print(String(data: data, encoding: .utf8)!)
|
// print(String(data: data, encoding: .utf8)!)
|
||||||
|
|
||||||
}
|
}
|
||||||
task.resume()
|
task.resume()
|
||||||
|
|
@ -739,7 +891,7 @@ class WifiViewModel: ObservableObject {
|
||||||
print(request.cURL(pretty: true))
|
print(request.cURL(pretty: true))
|
||||||
|
|
||||||
let task = URLSession.shared.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 {
|
||||||
completion(.failure(error))
|
completion(.failure(error))
|
||||||
|
|
@ -802,9 +954,6 @@ class WifiViewModel: ObservableObject {
|
||||||
|
|
||||||
func deleteRequest() {
|
func deleteRequest() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let username = ""
|
let username = ""
|
||||||
let password = "passw0rd"
|
let password = "passw0rd"
|
||||||
let loginString = "\(username):\(password)"
|
let loginString = "\(username):\(password)"
|
||||||
|
|
@ -843,6 +992,40 @@ class WifiViewModel: ObservableObject {
|
||||||
task.resume()
|
task.resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Published var projectDownloaded = false
|
||||||
|
@Published var failedProjectLaunch = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func getProjectForSubClass(nameOf project: String) {
|
||||||
|
|
||||||
|
if let enumerator = FileManager.default.enumerator(at: directoryPath, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
|
||||||
|
// for case condition: Only process URLs
|
||||||
|
for case let fileURL as URL in enumerator {
|
||||||
|
|
||||||
|
if fileURL.lastPathComponent == project {
|
||||||
|
failedProjectLaunch = false
|
||||||
|
projectDownloaded = true
|
||||||
|
print(#function)
|
||||||
|
print("Searching for... \(project)")
|
||||||
|
print("URL Path: \(fileURL.path)")
|
||||||
|
print("URL : \(fileURL)")
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
} else {
|
||||||
|
failedProjectLaunch = true
|
||||||
|
projectDownloaded = false
|
||||||
|
print("Project was not found...")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Enter IP Adress
|
// Enter IP Adress
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue