Ora Browser includes a powerful download manager that tracks active and recent downloads with detailed progress monitoring.
Download Manager Overview
The download manager provides real-time tracking of file downloads with progress indicators, history, and file management capabilities.
// From DownloadManager.swift:6-14
@MainActor
class DownloadManager : ObservableObject {
@Published var activeDownloads: [Download] = []
@Published var recentDownloads: [Download] = []
@Published var isDownloadsPopoverOpen = false
let modelContainer: ModelContainer
let modelContext: ModelContext
private var activeDownloadTasks: [UUID: WKDownload] = [ : ]
Key Features
Active Downloads Real-time progress tracking for ongoing downloads
Download History View and manage the last 20 downloads
File Operations Open downloads in Finder or manage files
Status Tracking Monitor pending, downloading, completed, failed, and cancelled states
Starting a Download
Downloads are automatically initiated when you click download links or save files:
// From DownloadManager.swift:39-66
func startDownload (
from downloadTask : WKDownload,
originalURL : URL,
suggestedFilename : String ,
expectedSize : Int64 = 0
) -> Download {
let download = Download (
originalURL : originalURL,
fileName : suggestedFilename,
fileSize : expectedSize
)
download. status = . downloading
download. isActive = true
// Save to SwiftData
modelContext. insert (download)
do {
try modelContext. save ()
} catch {
// Failed to save download
}
activeDownloadTasks[download. id ] = downloadTask
activeDownloads. append (download)
refreshRecentDownloads ()
return download
}
Download States
// From Download.swift:4-10
enum DownloadStatus : String , Codable {
case pending
case downloading
case completed
case failed
case cancelled
}
Download Progress
Real-time progress updates show download speed and completion status:
// From DownloadManager.swift:68-78
func updateDownloadProgress ( _ download : Download, downloadedBytes : Int64 , totalBytes : Int64 ) {
download. updateProgress ( downloadedBytes : downloadedBytes, totalBytes : totalBytes)
try ? modelContext. save ()
// Trigger UI updates
DispatchQueue. main . async {
self . objectWillChange . send ()
download. objectWillChange . send ()
}
}
Progress Tracking
Each download tracks detailed progress information:
// From Download.swift:54-65
func updateProgress ( downloadedBytes : Int64 , totalBytes : Int64 ) {
self . downloadedBytes = downloadedBytes
self . fileSize = totalBytes
self . progress = totalBytes > 0 ? Double (downloadedBytes) / Double (totalBytes) : 0.0
// Update published properties for UI
DispatchQueue. main . async {
self . displayDownloadedBytes = downloadedBytes
self . displayFileSize = totalBytes > 0 ? totalBytes : self . fileSize
self . displayProgress = self . progress
}
}
Progress updates happen on the main thread to ensure smooth UI updates without blocking the download.
Download Model
Each download is represented by a SwiftData model:
// From Download.swift:13-26
@Model
class Download : ObservableObject , Identifiable {
var id: UUID
var originalURL: URL
var originalURLString: String
var fileName: String
var fileSize: Int64
var downloadedBytes: Int64
var status: DownloadStatus
var progress: Double
var destinationURL: URL ?
var createdAt: Date
var completedAt: Date ?
var error: String ?
Download Properties
Property Type Description idUUID Unique identifier originalURLURL Source URL of the download fileNameString Name of the downloaded file fileSizeInt64 Total file size in bytes downloadedBytesInt64 Bytes downloaded so far statusDownloadStatus Current download state progressDouble Progress value (0.0 to 1.0) destinationURLURL? Where the file was saved createdAtDate When download started completedAtDate? When download finished errorString? Error message if failed
Completing Downloads
When a download finishes successfully:
// From DownloadManager.swift:80-90
func completeDownload ( _ download : Download, destinationURL : URL) {
download. markCompleted ( destinationURL : destinationURL)
try ? modelContext. save ()
activeDownloadTasks. removeValue ( forKey : download. id )
activeDownloads. removeAll { $0 . id == download. id }
refreshRecentDownloads ()
// Show notification or update UI
}
Completion Handler
// From Download.swift:67-73
func markCompleted ( destinationURL : URL) {
self . status = . completed
self . progress = 1.0
self . destinationURL = destinationURL
self . completedAt = Date ()
self . isActive = false
}
Cancelling Downloads
You can cancel active downloads at any time:
// From DownloadManager.swift:102-114
func cancelDownload ( _ download : Download) {
if let downloadTask = activeDownloadTasks[download. id ] {
downloadTask. cancel ()
}
download. markCancelled ()
try ? modelContext. save ()
activeDownloadTasks. removeValue ( forKey : download. id )
activeDownloads. removeAll { $0 . id == download. id }
refreshRecentDownloads ()
}
Access Downloads
Click the downloads icon in the toolbar
Find Active Download
Locate the download you want to cancel
Cancel
Click the cancel button next to the download
Confirm
The download stops immediately and is marked as cancelled
Handling Download Failures
When downloads fail, error information is preserved:
// From DownloadManager.swift:92-100
func failDownload ( _ download : Download, error : String ) {
download. markFailed ( error : error)
try ? modelContext. save ()
activeDownloadTasks. removeValue ( forKey : download. id )
activeDownloads. removeAll { $0 . id == download. id }
refreshRecentDownloads ()
}
Error Tracking
// From Download.swift:75-79
func markFailed ( error : String ) {
self . status = . failed
self . error = error
self . isActive = false
}
Failed downloads remain in the recent downloads list so you can retry them. Check the error message to understand what went wrong.
Download History
View your recent download history:
// From DownloadManager.swift:25-37
private func loadRecentDownloads () {
let descriptor = FetchDescriptor < Download > (
sortBy : [ SortDescriptor (\. createdAt , order : . reverse )]
)
do {
let downloads = try modelContext. fetch (descriptor)
self . recentDownloads = Array (downloads. prefix ( 20 )) // Show last 20 downloads
self . activeDownloads = downloads. filter { $0 . status == . downloading }
} catch {
// Failed to load downloads
}
}
The download history shows the last 20 downloads, sorted by creation date (newest first).
Clearing Completed Downloads
Remove completed downloads from the list:
// From DownloadManager.swift:116-124
func clearCompletedDownloads () {
let completedDownloads = recentDownloads. filter { $0 . status == . completed }
for download in completedDownloads {
modelContext. delete (download)
}
try ? modelContext. save ()
refreshRecentDownloads ()
}
File Operations
Opening in Finder
Quickly locate downloaded files:
// From DownloadManager.swift:137-140
func openDownloadInFinder ( _ download : Download) {
guard let destinationURL = download.destinationURL else { return }
NSWorkspace. shared . selectFile (destinationURL. path , inFileViewerRootedAtPath : "" )
}
Complete Download
Wait for the download to finish
Open Downloads List
Click the downloads icon in the toolbar
Show in Finder
Right-click the download and select “Show in Finder”
Deleting Downloads
Remove downloads from the list:
// From DownloadManager.swift:126-135
func deleteDownload ( _ download : Download) {
// If it's an active download, cancel it first
if download.status == .downloading {
cancelDownload (download)
}
modelContext. delete (download)
try ? modelContext. save ()
refreshRecentDownloads ()
}
Deleting a download from the list doesn’t delete the actual file from disk. To remove the file, delete it from Finder.
Download Location
Default Directory
// From DownloadManager.swift:147-150
func getDownloadsDirectory () -> URL {
return FileManager. default . urls ( for : . downloadsDirectory , in : . userDomainMask )
. first ?? URL ( fileURLWithPath : NSHomeDirectory ())
}
By default, files are saved to your macOS Downloads folder (~/Downloads).
Unique Filenames
Ora Browser prevents filename conflicts:
// From DownloadManager.swift:153-168
func createUniqueFilename ( for url : URL) -> URL {
var finalURL = url
var counter = 1
while FileManager.default. fileExists ( atPath : finalURL. path ) {
let filename = url. deletingPathExtension (). lastPathComponent
let ext = url. pathExtension
let directory = url. deletingLastPathComponent ()
let newFilename = ext. isEmpty ? " \( filename ) ( \( counter ) )" : " \( filename ) ( \( counter ) ). \( ext ) "
finalURL = directory. appendingPathComponent (newFilename)
counter += 1
}
return finalURL
}
If file.pdf exists, the next download is saved as file (1).pdf, then file (2).pdf, etc.
File sizes are displayed in human-readable format:
// From Download.swift:86-96
var formattedFileSize: String {
return ByteCountFormatter. string (
fromByteCount : displayFileSize > 0 ? displayFileSize : fileSize,
countStyle : . file
)
}
var formattedDownloadedSize: String {
return ByteCountFormatter. string ( fromByteCount : displayDownloadedBytes, countStyle : . file )
}
Examples:
1.5 MB instead of 1572864 bytes
3.2 GB instead of 3435973836 bytes
456 KB instead of 466944 bytes
UI Integration
The download manager is integrated into the browser UI:
Best Practices
Keep an eye on the download progress:
Check for completion notifications
Verify file integrity after download
Watch for error messages
Cancel slow or stuck downloads
Regularly clean up your download list:
Clear completed downloads periodically
Delete failed downloads after retry
Keep the list manageable (20 items max)
When downloads fail:
Check the error message
Verify your internet connection
Try downloading again
Check available disk space
Verify the source URL is still valid
Organize Downloaded Files
After downloading:
Move files to appropriate folders
Rename files for better organization
Delete files you no longer need
Back up important downloads
Troubleshooting
Download Won’t Start
Check your internet connection
Verify the source URL is accessible
Ensure you have write permissions to the Downloads folder
Check available disk space
Download Progress Stuck
Cancel and restart the download
Check network stability
Try downloading at a different time
Verify the server is responding
Downloaded File Won’t Open
Check if the download completed successfully
Verify the file isn’t corrupted (check file size)
Ensure you have the right app to open the file type
Try re-downloading the file
Can’t Find Downloaded File
Click “Show in Finder” from the downloads list
Check your Downloads folder manually
Search Spotlight for the filename
Verify the download actually completed
Privacy Considerations
Downloads from private browsing windows are tracked during the session but the history is cleared when you close the private window.
Private Mode Behavior
Download progress tracked normally
Files are saved to disk
Download history cleared on window close
File metadata not retained
Regular Mode
Full download history maintained
Last 20 downloads always visible
Download metadata persisted
Searchable download records