73 lines
2.2 KiB
Swift
73 lines
2.2 KiB
Swift
import SwiftUI
|
|
import SFSafeSymbols
|
|
|
|
struct UploadSheet: View {
|
|
|
|
@EnvironmentObject
|
|
private var content: Content
|
|
|
|
@EnvironmentObject
|
|
private var upload: RemotePush
|
|
|
|
@Environment(\.dismiss)
|
|
private var dismiss
|
|
|
|
@State
|
|
private var output: [String] = ["Ready to upload"]
|
|
|
|
private var uploadSymbol: SFSymbol {
|
|
if upload.isTransmittingToRemote {
|
|
return .squareAndArrowUpBadgeClock
|
|
}
|
|
if !upload.lastPushWasSuccessful {
|
|
return .squareAndArrowUpTrianglebadgeExclamationmark
|
|
}
|
|
return .squareAndArrowUp
|
|
}
|
|
|
|
var header: String {
|
|
let user = content.settings.general.remoteUserForUpload
|
|
let port = content.settings.general.remotePortForUpload
|
|
let url = content.settings.general.url.withHttpPrefixRemoved
|
|
let path = content.settings.general.remotePathForUpload.withLeadingSlashRemoved
|
|
return "\(user)@\(url):\(port)/\(path)"
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
HStack {
|
|
Button("Upload", action: startUpload)
|
|
.disabled(upload.isTransmittingToRemote)
|
|
Text(header)
|
|
Spacer()
|
|
Button("Close", action: { dismiss() })
|
|
}
|
|
ScrollView {
|
|
Text(output.joined(separator: "\n"))
|
|
.font(.body.monospaced())
|
|
.foregroundStyle(.primary)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
.padding()
|
|
.frame(minWidth: 500, idealWidth: 600)
|
|
}
|
|
|
|
private func startUpload() {
|
|
guard let folder = content.storage.outputScope?.url.path() else {
|
|
output = ["No output folder to start upload"]
|
|
return
|
|
}
|
|
output = ["Starting upload..."]
|
|
|
|
upload.transmitToRemote(
|
|
settings: content.settings.general,
|
|
outputFolder: folder) { newContent in
|
|
DispatchQueue.main.async {
|
|
let newLines = newContent.components(separatedBy: "\n").suffix(4)
|
|
self.output = (self.output + newLines).suffix(4)
|
|
}
|
|
}
|
|
}
|
|
}
|