From 2757eb169507f608e135820e05bd09f9721ca104 Mon Sep 17 00:00:00 2001 From: Zach Berger Date: Sun, 29 Nov 2020 12:29:13 -0800 Subject: [PATCH] Fix crash for when there are no services. --- Brewlet/AppDelegate.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Brewlet/AppDelegate.swift b/Brewlet/AppDelegate.swift index 38acfb9..310c188 100644 --- a/Brewlet/AppDelegate.swift +++ b/Brewlet/AppDelegate.swift @@ -384,11 +384,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, PreferencesDelegate { // Sync with brew let data = String(decoding: data, as: UTF8.self) let lines = data.split(separator: "\n") - for line in lines[1...] { - let parts = line.split(separator: " ", maxSplits: Int.max, omittingEmptySubsequences: true) - let package = parts[0] - let isStopped = parts[1] == "stopped" - services.append(Service(name: String(package), isStopped: isStopped)) + + // Check that there are services before parsing the output + if lines.count > 0 { + for line in lines[1...] { + let parts = line.split(separator: " ", maxSplits: Int.max, omittingEmptySubsequences: true) + let package = parts[0] + let isStopped = parts[1] == "stopped" + services.append(Service(name: String(package), isStopped: isStopped)) + } } // Update UI