-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More fixes and improvements, specially to the torrent file / magnet l…
…ink handlers.
- Loading branch information
Showing
9 changed files
with
446 additions
and
279 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Extensions/NewServerView+Extensions.swift → ...red Extensions/NewServerView+Shared.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
Shared/Views/Shared Extensions/TorrentHandlerView+Shared.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// | ||
// TorrentHandlerView+Shared.swift | ||
// SeedTruck | ||
// | ||
// Created by Eduardo Almeida on 12/12/2020. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension TorrentHandlerView { | ||
|
||
struct NoServersWarningView: View { | ||
|
||
var body: some View { | ||
GroupBox(label: Label("Oops!", systemImage: "exclamationmark.triangle")) { | ||
HStack { | ||
Text("You must first configure at least one server in the app in order to be able to add a torrent!") | ||
Spacer() | ||
}.padding(.top) | ||
} | ||
} | ||
} | ||
|
||
struct InfoSectionView: View { | ||
|
||
let torrent: LocalTorrent | ||
|
||
var body: some View { | ||
Group { | ||
if let name = torrent.name { | ||
HStack { | ||
Text("Name") | ||
Spacer() | ||
Text(name) | ||
.foregroundColor(.secondary) | ||
} | ||
} | ||
|
||
if let size = torrent.size { | ||
HStack { | ||
Text("Size") | ||
Spacer() | ||
Text(ByteCountFormatter.humanReadableFileSize(bytes: Int64(size))) | ||
.foregroundColor(.secondary) | ||
} | ||
} | ||
|
||
if let files = torrent.files { | ||
HStack { | ||
Text("Files") | ||
Spacer() | ||
Text("\(files.count)") | ||
.foregroundColor(.secondary) | ||
} | ||
} | ||
|
||
if let isPrivate = torrent.isPrivate { | ||
HStack { | ||
Text("Private") | ||
Spacer() | ||
Text(isPrivate ? "Yes" : "No") | ||
.foregroundColor(.secondary) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
var showingError: Binding<Bool> { | ||
Binding<Bool>( | ||
get: { errorMessage != nil }, | ||
set: { | ||
if $0 == false { | ||
errorMessage = nil | ||
} | ||
} | ||
) | ||
} | ||
|
||
func onAppear() { | ||
if let s = server { | ||
selectedServers = [s] | ||
} else if serverConnections.count == 1 { | ||
selectedServers = [serverConnections[0]] | ||
} | ||
} | ||
|
||
func startDownload() { | ||
processing = true | ||
|
||
var remaining = selectedServers.count | ||
var errors: [(Server, Error)] = [] | ||
|
||
selectedServers.forEach { server in | ||
server.connection.addTorrent(torrent) { | ||
switch $0 { | ||
case .success: | ||
() | ||
|
||
case .failure(let error): | ||
errors.append((server, error)) | ||
} | ||
|
||
remaining = remaining - 1 | ||
|
||
if remaining == 0 { | ||
processing = false | ||
|
||
if errors.count == 0 { | ||
closeHandler?() | ||
} else { | ||
errorMessage = "An error has occurred while adding the torrent to the following servers:\n\n" + | ||
"\(errors.map { "\"\($0.0.name)\": \($0.1.localizedDescription)\n" })\n" + | ||
"Please look at the inserted data and try again." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
var processingBody: some View { | ||
ProgressView() | ||
.progressViewStyle(CircularProgressViewStyle()) | ||
.padding() | ||
} | ||
|
||
var sharedBody: some View { | ||
Group { | ||
if processing { | ||
processingBody | ||
} else { | ||
normalBody | ||
} | ||
} | ||
.navigationTitle("Add Torrent") | ||
.padding() | ||
.onAppear(perform: onAppear) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.