Skip to content

Commit

Permalink
feat: use better approach to check SourceTree's installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Saiya committed Dec 30, 2022
1 parent 054e097 commit 7094091
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Binary file modified SourceTree.alfredworkflow
Binary file not shown.
10 changes: 9 additions & 1 deletion workflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ class SourceTree: Workflow {

emptyMessage = AlfredItem(title: "Your SourceTree Bookmark Is Empty ", subtitle: "Please add repos to SourceTree first")

guard let data = try? Data(contentsOf: Self.plistPath) else {
guard Self.isSourceTreeInstalled() else {
errorMessage = AlfredItem(title: "SourceTree not installed", subtitle: "Press enter to open SourceTree homepage and download it", arg: "open \"https://sourcetreeapp.com/\"")
return
}
guard let data = try? Data(contentsOf: Self.plistPath) else {
errorMessage = emptyMessage
return
}

do {
let parsed = try PropertyListDecoder().decode(SourceTreePlist.self, from: data)
Expand Down Expand Up @@ -237,6 +241,10 @@ class SourceTree: Workflow {
let url = FileManager.default.homeDirectoryForCurrentUser
return url.appendingPathComponent("Library/Application Support/SourceTree/browser.plist")
}

static func isSourceTreeInstalled() -> Bool {
return FileManager.default.fileExists(atPath: "/Applications/SourceTree.app")
}
}

// MARK: SourceTree Plist
Expand Down

0 comments on commit 7094091

Please sign in to comment.