Add an ApplicationInventory singleton to cache application invemory data so we don't re-generate it all the time

This commit is contained in:
Greg Neagle
2024-08-19 09:51:28 -07:00
parent c38504d16b
commit 6fcb63d074
+26 -1
View File
@@ -141,7 +141,7 @@ func spApplicationData() async -> PlistDict {
return applicationData
}
func appData() -> [[String: String]] {
func getAppData() -> [[String: String]] {
// Gets info on currently installed apps.
// Returns a list of dicts containing path, name, version and bundleid
@@ -192,6 +192,31 @@ func appData() -> [[String: String]] {
return applicationData
}
class ApplicationInventory {
// a Singleton class for application inventory info, since it's expensive
// to generate
static let shared = ApplicationInventory()
var inventory: [[String: String]]
private init() {
inventory = getAppData()
}
func get() -> [[String: String]] {
return inventory
}
func rescan() {
// force a rescan of app inventory
inventory = getAppData()
}
}
func appData() -> [[String: String]] {
return ApplicationInventory.shared.get()
}
func filteredAppData() -> [[String: String]] {
// Returns a filtered version of app_data, filtering out apps in user
// home directories for use by compare_application_version()