Forked from mminer/DownloadProgressIndicatorDemo.swift
Last active
July 9, 2024 17:56
-
-
Save amomchilov/7a977b9f99e898f0ff5d8e500c213aef to your computer and use it in GitHub Desktop.
Displays a progress indicator on a file in the Finder.
This file contains hidden or 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
import Cocoa | |
let path = "/Users/You/Pick/Any/Random/File/On/Your/System.txt" | |
let destination = URL(fileURLWithPath: path) | |
let progress: Progress = { | |
let p = Progress(parent: nil, userInfo: [ | |
.fileOperationKindKey: Progress.FileOperationKind.downloading, | |
.fileURLKey: destination, | |
]) | |
p.isCancellable = true | |
p.isPausable = false | |
p.kind = .file | |
p.totalUnitCount = 10 | |
p.publish() | |
return p | |
}() | |
// Simulate downloading a file. | |
let timer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { _ in | |
progress.completedUnitCount += 1 | |
print("\(progress.completedUnitCount) / \(progress.totalUnitCount)") | |
if progress.completedUnitCount == progress.totalUnitCount { | |
Darwin.exit(0) | |
} | |
} | |
RunLoop.current.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slight modification for continued animation: