mirror of https://github.com/buresdv/Cork
~ Reveal in Finder implementation
Previously, a package's Reveal in Finder method would find its URL from scratch.
Now that a URL property is present, this is no longer necessary.
(cherry picked from commit 086e4dc526)
This commit is contained in:
parent
1a908ad8a5
commit
f3ec8a2be6
|
|
@ -17330,6 +17330,7 @@
|
|||
}
|
||||
},
|
||||
"error.finder-reveal.could-not-find-package-in-parent" : {
|
||||
"extractionState" : "stale",
|
||||
"localizations" : {
|
||||
"cs" : {
|
||||
"stringUnit" : {
|
||||
|
|
@ -17375,6 +17376,17 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"error.finder-reveal.no-url" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Package has no URL"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"error.generic-couldnt-decode-json.%@" : {
|
||||
"localizations" : {
|
||||
"cs" : {
|
||||
|
|
|
|||
|
|
@ -111,50 +111,24 @@ struct BrewPackage: Identifiable, Equatable, Hashable, Codable
|
|||
{
|
||||
enum FinderRevealError: LocalizedError
|
||||
{
|
||||
case couldNotFindPackageInParent
|
||||
case noURL
|
||||
|
||||
var errorDescription: String?
|
||||
{
|
||||
return String(localized: "error.finder-reveal.could-not-find-package-in-parent")
|
||||
return String(localized: "error.finder-reveal.no-url")
|
||||
}
|
||||
}
|
||||
|
||||
var packageURL: URL?
|
||||
var packageLocationParent: URL
|
||||
{
|
||||
if type == .formula
|
||||
{
|
||||
return AppConstants.shared.brewCellarPath
|
||||
}
|
||||
else
|
||||
{
|
||||
return AppConstants.shared.brewCaskPath
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
let contentsOfParentFolder: [URL] = try FileManager.default.contentsOfDirectory(at: packageLocationParent, includingPropertiesForKeys: [.isDirectoryKey])
|
||||
|
||||
packageURL = contentsOfParentFolder.filter
|
||||
{
|
||||
$0.lastPathComponent.contains(name)
|
||||
}.first
|
||||
|
||||
guard let packageURL
|
||||
else
|
||||
{
|
||||
throw FinderRevealError.couldNotFindPackageInParent
|
||||
}
|
||||
|
||||
packageURL.revealInFinder(.openParentDirectoryAndHighlightTarget)
|
||||
}
|
||||
catch let finderRevealError
|
||||
guard let url = url else
|
||||
{
|
||||
let finderRevealError: FinderRevealError = .noURL
|
||||
AppConstants.shared.logger.error("Failed while revealing package: \(finderRevealError.localizedDescription)")
|
||||
/// Play the error sound
|
||||
NSSound(named: "ping")?.play()
|
||||
throw finderRevealError
|
||||
}
|
||||
|
||||
url.revealInFinder(.openParentDirectoryAndHighlightTarget)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue