Skip to content

Commit

Permalink
Merge pull request #15 from zenangst/add/finder-to-list-of-applications
Browse files Browse the repository at this point in the history
Add Finder to list of applications
  • Loading branch information
RamonGilabert authored Sep 30, 2018
2 parents d83f274 + e37ca18 commit 432f38c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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.2.0</string>
<string>0.2.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
Expand Down
14 changes: 8 additions & 6 deletions Sources/Applications/ApplicationsLogicController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class ApplicationsLogicController {
in: .localDomainMask,
appropriateFor: nil,
create: false)
let urls = try FileManager.default.contentsOfDirectory(at: applicationDirectory,
var urls = try FileManager.default.contentsOfDirectory(at: applicationDirectory,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles)
let sortedUrls = urls.sorted(by: { $0.absoluteString.lowercased() < $1.absoluteString.lowercased() } )
let applications = try processApplications(sortedUrls, at: applicationDirectory)
urls.append(URL(string: "file:///System/Library/CoreServices/Finder.app")!)
let applications = try processApplications(urls, at: applicationDirectory)
handler(.list(applications))
} catch {}
}
Expand All @@ -31,7 +31,7 @@ class ApplicationsLogicController {
do {
let shell = Shell()
let applicationIsRunning = !NSRunningApplication.runningApplications(withBundleIdentifier: application.bundleIdentifier).isEmpty
if applicationIsRunning {
if applicationIsRunning && !application.url.path.contains("CoreServices") {
do {
let script = """
tell application "\(application.name)" to quit
Expand All @@ -42,8 +42,10 @@ class ApplicationsLogicController {

try shell.execute(command: "defaults write \(application.bundleIdentifier) NSRequiresAquaSystemAppearance -bool \(newSetting)")

if applicationIsRunning {
if applicationIsRunning && !application.url.path.contains("CoreServices") {
NSWorkspace.shared.launchApplication(application.name)
} else {
try shell.execute(command: "killall", arguments: ["-9", "\(application.name)"])
}

DispatchQueue.main.async { [weak self] in
Expand Down Expand Up @@ -91,7 +93,7 @@ class ApplicationsLogicController {
appearance: resolvedPlist.appearance())
applications.append(app)
}
return applications
return applications.sorted(by: { $0.name.lowercased() < $1.name.lowercased() })
}
}

Expand Down

0 comments on commit 432f38c

Please sign in to comment.