Skip to content

Commit

Permalink
fix(Core): check home application path
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji4n1ng committed Jul 21, 2019
1 parent ab3a9e3 commit 2bd4301
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion OpenInTerminalCore/FinderManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,21 @@ public class FinderManager {

/// Determine if the app exists in the `/Applications` folder
private func applicationExists(_ application: String) -> Bool {
let applicationDir = "/Applications"

var homeApplicationDirURL: URL
if #available(OSX 10.12, *) {
homeApplicationDirURL = FileManager.default.homeDirectoryForCurrentUser
} else {
// Fallback on earlier versions
homeApplicationDirURL = URL(fileURLWithPath: NSHomeDirectory())
}
homeApplicationDirURL.appendPathComponent("Applications")

do {
return try FileManager.default.contentsOfDirectory(atPath: "/Applications").contains("\(application).app")
let isInApplication = try FileManager.default.contentsOfDirectory(atPath: applicationDir ).contains("\(application).app")
let isInHomeApplication = try FileManager.default.contentsOfDirectory(atPath: homeApplicationDirURL.path).contains("\(application).app")
return isInApplication || isInHomeApplication
} catch {
return false
}
Expand Down

0 comments on commit 2bd4301

Please sign in to comment.