diff --git a/phpmon/Common/PHP/Homebrew/HomebrewService.swift b/phpmon/Common/PHP/Homebrew/HomebrewService.swift index 75c1d84..e11ad69 100644 --- a/phpmon/Common/PHP/Homebrew/HomebrewService.swift +++ b/phpmon/Common/PHP/Homebrew/HomebrewService.swift @@ -20,16 +20,19 @@ struct HomebrewService: Decodable, Equatable { let error_log_path: String? public static func loadAll( - filter: [String] = [PhpEnv.phpInstall.formula, "nginx", "dnsmasq"] - ) async -> [HomebrewService] { - return try! JSONDecoder().decode( - [HomebrewService].self, - from: Shell.pipe( - "sudo \(Paths.brew) services info --all --json", - requiresPath: true - ).data(using: .utf8)! - ).filter({ service in - return filter.contains(service.name) - }) + filter: [String] = [PhpEnv.phpInstall.formula, "nginx", "dnsmasq"], + completion: @escaping ([HomebrewService]) -> Void + ) { + DispatchQueue.global(qos: .background).async { + let data = Shell + .pipe("sudo \(Paths.brew) services info --all --json", requiresPath: true) + .data(using: .utf8)! + + let services = try! JSONDecoder() + .decode([HomebrewService].self, from: data) + .filter({ return filter.contains($0.name) }) + + completion(services) + } } } diff --git a/phpmon/Domain/Menu/ServicesView.swift b/phpmon/Domain/Menu/ServicesView.swift index a3f7c87..5921090 100644 --- a/phpmon/Domain/Menu/ServicesView.swift +++ b/phpmon/Domain/Menu/ServicesView.swift @@ -46,14 +46,15 @@ class ServicesView: NSView, XibLoadable { } @objc func updateInformation() { - Task { await self.loadData() } + self.loadData() } - func loadData() async { - self.applyAllInfoFieldsFromCachedValue() - let services = await HomebrewService.loadAll() - ServicesView.services = Dictionary(uniqueKeysWithValues: services.map{ ($0.name, $0) }) + func loadData() { self.applyAllInfoFieldsFromCachedValue() + HomebrewService.loadAll { services in + ServicesView.services = Dictionary(uniqueKeysWithValues: services.map{ ($0.name, $0) }) + self.applyAllInfoFieldsFromCachedValue() + } } func applyAllInfoFieldsFromCachedValue() {