Skip to content

Commit

Permalink
Fix crash for when there are no services.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachberger committed Nov 29, 2020
1 parent 55fe713 commit 2757eb1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Brewlet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2757eb1

Please sign in to comment.