Skip to content

Commit

Permalink
Clean up download file on dismissing download manager (#3181)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal authored Nov 20, 2024
1 parent d193ee0 commit 4b866ee
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions Sources/App/WebView/DownloadManager/DownloadManagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,59 @@ struct DownloadManagerView: View {

var body: some View {
VStack(spacing: .zero) {
HStack {
Button(action: {
viewModel.cancelDownload()
viewModel.deleteFile()
dismiss()
}, label: {
Image(systemSymbol: .xmarkCircleFill)
.font(.title)
.foregroundStyle(
Color(uiColor: .systemBackground),
.gray.opacity(0.5)
)
})
.buttonStyle(.plain)
.frame(maxWidth: .infinity, alignment: .trailing)
.padding()
}
if viewModel.finished {
successView
} else if viewModel.failed {
fileCard
failedCard
} else {
ProgressView()
.progressViewStyle(.circular)
.scaleEffect(2)
.padding(Spaces.four)
Text(L10n.DownloadManager.Downloading.title)
.font(.title.bold())
fileCard
Text(viewModel.progress)
.animation(.easeInOut(duration: 1), value: viewModel.progress)
}
closeButton
content
Spacer()
}
.onDisappear {
viewModel.cancelDownload()
viewModel.deleteFile()
}
.onChange(of: viewModel.finished) { _, newValue in
if newValue, Current.isCatalyst {
UIApplication.shared.open(AppConstants.DownloadsDirectory)
}
}
}

@ViewBuilder
private var content: some View {
if viewModel.finished {
successView
} else if viewModel.failed {
fileCard
failedCard
} else {
ProgressView()
.progressViewStyle(.circular)
.scaleEffect(2)
.padding(Spaces.four)
Text(L10n.DownloadManager.Downloading.title)
.font(.title.bold())
fileCard
Text(viewModel.progress)
.animation(.easeInOut(duration: 1), value: viewModel.progress)
}
}

private var closeButton: some View {
HStack {
Button(action: {
dismiss()
}, label: {
Image(systemSymbol: .xmarkCircleFill)
.font(.title)
.foregroundStyle(
Color(uiColor: .systemBackground),
.gray.opacity(0.5)
)
})
.buttonStyle(.plain)
.frame(maxWidth: .infinity, alignment: .trailing)
.padding()
}
}

private var successView: some View {
VStack(spacing: Spaces.three) {
Image(systemSymbol: .checkmark)
Expand Down

0 comments on commit 4b866ee

Please sign in to comment.