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" : {
|
"error.finder-reveal.could-not-find-package-in-parent" : {
|
||||||
|
"extractionState" : "stale",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"cs" : {
|
"cs" : {
|
||||||
"stringUnit" : {
|
"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.%@" : {
|
"error.generic-couldnt-decode-json.%@" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"cs" : {
|
"cs" : {
|
||||||
|
|
|
||||||
|
|
@ -111,50 +111,24 @@ struct BrewPackage: Identifiable, Equatable, Hashable, Codable
|
||||||
{
|
{
|
||||||
enum FinderRevealError: LocalizedError
|
enum FinderRevealError: LocalizedError
|
||||||
{
|
{
|
||||||
case couldNotFindPackageInParent
|
case noURL
|
||||||
|
|
||||||
var errorDescription: String?
|
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?
|
guard let url = url else
|
||||||
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
|
|
||||||
{
|
{
|
||||||
|
let finderRevealError: FinderRevealError = .noURL
|
||||||
AppConstants.shared.logger.error("Failed while revealing package: \(finderRevealError.localizedDescription)")
|
AppConstants.shared.logger.error("Failed while revealing package: \(finderRevealError.localizedDescription)")
|
||||||
/// Play the error sound
|
/// Play the error sound
|
||||||
NSSound(named: "ping")?.play()
|
NSSound(named: "ping")?.play()
|
||||||
|
throw finderRevealError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
url.revealInFinder(.openParentDirectoryAndHighlightTarget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue