Skip to content

Commit

Permalink
Merge pull request #49 from zenangst/feature/recursive-parsing-of-app…
Browse files Browse the repository at this point in the history
…lications

Implement recursive parsing of applications
  • Loading branch information
zenangst authored Oct 20, 2018
2 parents 17ae42e + f1346de commit ff24d22
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .current-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.2
0.9.3
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img src="https://github.com/zenangst/Gray/blob/master/Resources/Assets.xcassets/AppIcon.appiconset/icon_256x256.png?raw=true" alt="Gray Icon" align="right" />

Current version: 0.9.2 [[Download](https://github.com/zenangst/Gray/releases/download/0.9.2/Gray.zip)]
Current version: 0.9.3 [[Download](https://github.com/zenangst/Gray/releases/download/0.9.3/Gray.zip)]

Ever wanted to have light and dark apps live side-by-side in harmony? Well, now you can. With **Gray** you can pick between the light appearance and the dark appearance on a per-app basis with the click of a button.

Expand Down
2 changes: 1 addition & 1 deletion Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.9.2</string>
<string>0.9.3</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ class ApplicationsLogicController {
func load(then handler: (ApplicationsViewController.State) -> Void) {
do {
let excludedBundles = ["com.vmware.fusion"]

var applicationUrls = [URL]()
applicationUrls.append(URL(string: "file:///System/Library/CoreServices/Finder.app")!)
for url in try applicationLocations() {
guard FileManager.default.fileExists(atPath: url.path) else { continue }
do {
let urls = try FileManager.default.contentsOfDirectory(at: url,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles)
applicationUrls.append(contentsOf: urls)
} catch {}
for path in try applicationLocations() {
applicationUrls.append(contentsOf: recursiveParse(at: path))
}

applicationUrls.append(URL(string: "file:///System/Library/CoreServices/Finder.app")!)
let applications = try parseApplicationUrls(applicationUrls, excludedBundles: excludedBundles)
handler(.view(applications))
} catch {}
Expand Down Expand Up @@ -96,12 +88,30 @@ class ApplicationsLogicController {
appropriateFor: nil,
create: false)
directories.append(applicationDirectory)
directories.append(applicationDirectory.appendingPathComponent("Utilities"))
directories.append(applicationDirectory.appendingPathComponent("Xcode.app/Contents/Applications"))

return directories
}

private func recursiveParse(at url: URL) -> [URL] {
var result = [URL]()
guard FileManager.default.fileExists(atPath: url.path),
let contents = try? FileManager.default.contentsOfDirectory(at: url,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles) else { return [] }
for file in contents {
var isDirectory: ObjCBool = true
let isFolder = FileManager.default.fileExists(atPath: file.path, isDirectory: &isDirectory)
if isFolder && file.pathExtension != "app" {
result.append(contentsOf: recursiveParse(at: file))
} else {
result.append(file)
}
}

return result
}

private func parseApplicationUrls(_ appUrls: [URL],
excludedBundles: [String] = []) throws -> [Application] {
var applications = [Application]()
Expand Down

0 comments on commit ff24d22

Please sign in to comment.