Skip to content

Commit 7094091

Browse files
author
Saiya
committed
feat: use better approach to check SourceTree's installation
1 parent 054e097 commit 7094091

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: SourceTree.alfredworkflow

-24.8 KB
Binary file not shown.

Diff for: workflow.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,14 @@ class SourceTree: Workflow {
163163

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

166-
guard let data = try? Data(contentsOf: Self.plistPath) else {
166+
guard Self.isSourceTreeInstalled() else {
167167
errorMessage = AlfredItem(title: "SourceTree not installed", subtitle: "Press enter to open SourceTree homepage and download it", arg: "open \"https://sourcetreeapp.com/\"")
168168
return
169169
}
170+
guard let data = try? Data(contentsOf: Self.plistPath) else {
171+
errorMessage = emptyMessage
172+
return
173+
}
170174

171175
do {
172176
let parsed = try PropertyListDecoder().decode(SourceTreePlist.self, from: data)
@@ -237,6 +241,10 @@ class SourceTree: Workflow {
237241
let url = FileManager.default.homeDirectoryForCurrentUser
238242
return url.appendingPathComponent("Library/Application Support/SourceTree/browser.plist")
239243
}
244+
245+
static func isSourceTreeInstalled() -> Bool {
246+
return FileManager.default.fileExists(atPath: "/Applications/SourceTree.app")
247+
}
240248
}
241249

242250
// MARK: SourceTree Plist

0 commit comments

Comments
 (0)