feat: rank built-in commands alongside applications
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import Foundation
|
||||
|
||||
public struct Application: Identifiable, Sendable {
|
||||
public enum Command: String, CaseIterable, Sendable {
|
||||
case translate
|
||||
}
|
||||
public static let commands = Command.allCases.map { Application(command: $0) }
|
||||
public let command: Command?
|
||||
public var id: URL { url }
|
||||
public let url: URL
|
||||
public let name: String
|
||||
@@ -12,8 +17,16 @@ public struct Application: Identifiable, Sendable {
|
||||
self.init(canonicalURL: url.standardizedFileURL.resolvingSymlinksInPath(), name: name)
|
||||
}
|
||||
|
||||
fileprivate init(canonicalURL: URL, name: String) {
|
||||
url = canonicalURL.hasDirectoryPath
|
||||
public init(command: Command) {
|
||||
let name = switch command {
|
||||
case .translate: "Conjure Translate"
|
||||
}
|
||||
self.init(canonicalURL: URL(string: "conjure-command://\(command.rawValue)")!, name: name, command: command)
|
||||
}
|
||||
|
||||
fileprivate init(canonicalURL: URL, name: String, command: Command? = nil) {
|
||||
self.command = command
|
||||
url = command != nil || canonicalURL.hasDirectoryPath
|
||||
? canonicalURL : URL(fileURLWithPath: canonicalURL.path, isDirectory: true)
|
||||
self.name = name
|
||||
searchableName = folded(name)
|
||||
@@ -178,5 +191,5 @@ func alphabetical(_ lhs: Application, _ rhs: Application) -> Bool {
|
||||
let order = lhs.name.localizedStandardCompare(rhs.name)
|
||||
if order != .orderedSame { return order == .orderedAscending }
|
||||
if lhs.name != rhs.name { return lhs.name < rhs.name }
|
||||
return lhs.url.path < rhs.url.path
|
||||
return lhs.url.absoluteString < rhs.url.absoluteString
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user