From e7cc642a869c86011f9a9e7291626319aa9721ef Mon Sep 17 00:00:00 2001 From: Andrew Nicolaou Date: Sun, 1 May 2016 14:55:33 +0200 Subject: [PATCH] Fetch up-to-date services list before showing menu --- .../xcschemes/BrewServicesMenubar.xcscheme | 2 +- BrewServicesMenubar/AppDelegate.swift | 102 +++++++++++------- 2 files changed, 64 insertions(+), 40 deletions(-) diff --git a/BrewServicesMenubar.xcodeproj/xcuserdata/andrew.xcuserdatad/xcschemes/BrewServicesMenubar.xcscheme b/BrewServicesMenubar.xcodeproj/xcuserdata/andrew.xcuserdatad/xcschemes/BrewServicesMenubar.xcscheme index 7508e1e..9e308c9 100644 --- a/BrewServicesMenubar.xcodeproj/xcuserdata/andrew.xcuserdatad/xcschemes/BrewServicesMenubar.xcscheme +++ b/BrewServicesMenubar.xcodeproj/xcuserdata/andrew.xcuserdatad/xcschemes/BrewServicesMenubar.xcscheme @@ -42,7 +42,7 @@ [Service] { let task = NSTask() let outpipe = NSPipe() @@ -79,45 +131,17 @@ class AppDelegate: NSObject, NSApplicationDelegate { return [] } - func controlService(name:String, state:String) { - let task = NSTask() - let outpipe = NSPipe() - task.standardOutput = outpipe - - task.launchPath = "/usr/local/bin/brew" - task.arguments = ["services", state, name] - task.launch() - } - + let matcher = "([^ ]+)([^ ]+)" + func parseServiceList(raw: String) -> [Service] { - let r = "([^ ]+)([^ ]+)" - var services = [Service]() let rawServices = raw.componentsSeparatedByString("\n") - for s in rawServices { - let parts = matchesForRegexInText(r, text: s) - let service = Service(name: parts[0], state: parts[1]) - services.append(service) - } - return services + return rawServices[1.. Service { + let parts = matchesForRegexInText(matcher, text: raw) + let service = Service(name: parts[0], state: parts[1]) + return service; } }