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
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ public final class LaunchHistory {
|
||||
self.defaults = defaults
|
||||
self.now = now
|
||||
for (identifier, value) in defaults.dictionary(forKey: Self.storageKey) ?? [:] {
|
||||
guard let url = URL(string: identifier), url.isFileURL,
|
||||
guard let url = URL(string: identifier),
|
||||
url.isFileURL || Application.commands.contains(where: { $0.id == url }),
|
||||
let record = value as? [String: Any],
|
||||
let count = record["count"] as? Int, count > 0,
|
||||
let lastLaunch = record["lastLaunch"] as? Date,
|
||||
@@ -26,7 +27,8 @@ public final class LaunchHistory {
|
||||
usage[url] = Usage(count: count, lastLaunch: lastLaunch)
|
||||
}
|
||||
for identifier in defaults.stringArray(forKey: Self.favoritesStorageKey) ?? [] {
|
||||
guard let url = URL(string: identifier), url.isFileURL else { continue }
|
||||
guard let url = URL(string: identifier),
|
||||
url.isFileURL || Application.commands.contains(where: { $0.id == url }) else { continue }
|
||||
favorites.insert(url)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user