Skip to content

Commit 1b0bfa1

Browse files
authored
Use macOS download folder instead of caches for downloads (#3659)
1 parent 5592f41 commit 1b0bfa1

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Sources/App/WebView/DownloadManager/DownloadManagerView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ struct DownloadManagerView: View {
2020
}
2121
.onDisappear {
2222
viewModel.cancelDownload()
23-
viewModel.deleteFile()
23+
24+
// For mac the file should remain in the download folder to keep expected behavior
25+
if !Current.isCatalyst {
26+
viewModel.deleteFile()
27+
}
2428
}
2529
.onChange(of: viewModel.finished) { _, newValue in
2630
if newValue, Current.isCatalyst {

Sources/Shared/Environment/AppConstants.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,28 @@ public enum AppConstants {
229229
}
230230

231231
public static var DownloadsDirectory: URL {
232-
let fileManager = FileManager.default
233-
let directoryURL = FileManager.default.urls(for: .cachesDirectory, in: .allDomainsMask).first!
234-
.appendingPathComponent(
232+
var directoryURL: URL = FileManager.default.urls(for: .cachesDirectory, in: .allDomainsMask).first!
233+
234+
// Save directly in macOS Downloads folder if running on Catalyst and allowed access to download folder when
235+
// prompted.
236+
if Current.isCatalyst, let macDownloadFolder = FileManager.default.urls(
237+
for: .downloadsDirectory,
238+
in: .userDomainMask
239+
).first {
240+
directoryURL = macDownloadFolder
241+
} else {
242+
directoryURL = directoryURL.appendingPathComponent(
235243
"Downloads",
236244
isDirectory: true
237245
)
238-
239-
if !fileManager.fileExists(atPath: directoryURL.path) {
246+
}
247+
if !FileManager.default.fileExists(atPath: directoryURL.path) {
240248
do {
241-
try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
249+
try FileManager.default.createDirectory(
250+
at: directoryURL,
251+
withIntermediateDirectories: true,
252+
attributes: nil
253+
)
242254
} catch {
243255
fatalError("Error while attempting to create downloads path URL: \(error)")
244256
}

0 commit comments

Comments
 (0)