diff --git a/BrewServicesMenubar.xcodeproj/project.pbxproj b/BrewServicesMenubar.xcodeproj/project.pbxproj index df7ed59..a9d5f15 100644 --- a/BrewServicesMenubar.xcodeproj/project.pbxproj +++ b/BrewServicesMenubar.xcodeproj/project.pbxproj @@ -90,6 +90,7 @@ TargetAttributes = { 49ED77AD1CD4B524000B4479 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0820; }; }; }; @@ -237,6 +238,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = andrewnicolaou.BrewServicesMenubar; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -249,6 +251,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = andrewnicolaou.BrewServicesMenubar; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -271,6 +274,7 @@ 49ED77BD1CD4B525000B4479 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/BrewServicesMenubar/AppDelegate.swift b/BrewServicesMenubar/AppDelegate.swift index fd5b39f..e244109 100644 --- a/BrewServicesMenubar/AppDelegate.swift +++ b/BrewServicesMenubar/AppDelegate.swift @@ -13,13 +13,13 @@ struct Service { var state = "unknown" // "started", "stopped", "unknown" } -func matchesForRegexInText(regex: String!, text: String!) -> [String] { +func matchesForRegexInText(_ regex: String!, text: String!) -> [String] { do { let regex = try NSRegularExpression(pattern: regex, options: []) let nsString = text as NSString - let results = regex.matchesInString(text, + let results = regex.matches(in: text, options: [], range: NSMakeRange(0, nsString.length)) - return results.map { nsString.substringWithRange($0.range)} + return results.map { nsString.substring(with: $0.range)} } catch let error as NSError { print("invalid regex: \(error.localizedDescription)") return [] @@ -34,11 +34,12 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var statusMenu: NSMenu! // Returns a status item from the system menu bar of variable length - let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1) + let statusItem = NSStatusBar.system().statusItem(withLength: -1) var services = [Service]() - func applicationDidFinishLaunching(aNotification: NSNotification) { - let icon = NSImage(named: "statusIcon") + func applicationDidFinishLaunching(_ aNotification: Notification) { + let icon = NSImage(named: "icon") + icon?.isTemplate = true if let button = statusItem.button { button.image = icon @@ -48,14 +49,14 @@ class AppDelegate: NSObject, NSApplicationDelegate { queryServicesAndUpdateMenu() } - func applicationWillTerminate(aNotification: NSNotification) { + func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } // // Event handlers for UI actions // - func handleClick(sender: NSMenuItem) { + func handleClick(_ sender: NSMenuItem) { if (sender.state == NSOnState) { sender.state = NSOffState controlService(sender.title, state: "stop") @@ -65,13 +66,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } - func handleQuit(sender: NSMenuItem) { - NSApplication.sharedApplication().terminate(nil) + func handleQuit(_ sender: NSMenuItem) { + NSApplication.shared().terminate(nil) } - func handleMenuOpen(sender: AnyObject?) { + func handleMenuOpen(_ sender: AnyObject?) { queryServicesAndUpdateMenu() - statusItem.popUpStatusItemMenu(statusMenu) + statusItem.popUpMenu(statusMenu) } // @@ -86,7 +87,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } statusMenu.addItem(item) } - statusMenu.addItem(NSMenuItem.separatorItem()) + statusMenu.addItem(NSMenuItem.separator()) let quit = NSMenuItem.init(title: "Quit", action:#selector(AppDelegate.handleQuit(_:)), keyEquivalent: "q") statusMenu.addItem(quit) } @@ -99,9 +100,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { // // Changes a service state // - func controlService(name:String, state:String) { - let task = NSTask() - let outpipe = NSPipe() + func controlService(_ name:String, state:String) { + let task = Process() + let outpipe = Pipe() task.standardOutput = outpipe task.launchPath = "/usr/local/bin/brew" @@ -114,8 +115,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { // brew services list // func serviceStates() -> [Service] { - let task = NSTask() - let outpipe = NSPipe() + let task = Process() + let outpipe = Pipe() task.standardOutput = outpipe task.launchPath = "/usr/local/bin/brew" @@ -123,8 +124,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { task.launch() let outdata = outpipe.fileHandleForReading.readDataToEndOfFile() - if var string = String.fromCString(UnsafePointer(outdata.bytes)) { - string = string.stringByTrimmingCharactersInSet(NSCharacterSet.newlineCharacterSet()) + if var string = String(data: outdata, encoding: String.Encoding.utf8) { + string = string.trimmingCharacters(in: CharacterSet.newlines) return parseServiceList(string) } @@ -133,12 +134,12 @@ class AppDelegate: NSObject, NSApplicationDelegate { let matcher = "([^ ]+)([^ ]+)" - func parseServiceList(raw: String) -> [Service] { - let rawServices = raw.componentsSeparatedByString("\n") + func parseServiceList(_ raw: String) -> [Service] { + let rawServices = raw.components(separatedBy: "\n") return rawServices[1.. Service { + func parseService(_ raw:String) -> Service { let parts = matchesForRegexInText(matcher, text: raw) let service = Service(name: parts[0], state: parts[1]) return service; diff --git a/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/Contents.json b/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/Contents.json index 2db2b1c..c0838e4 100644 --- a/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -41,13 +41,15 @@ "scale" : "2x" }, { - "idiom" : "mac", "size" : "512x512", + "idiom" : "mac", + "filename" : "appIcon.png", "scale" : "1x" }, { - "idiom" : "mac", "size" : "512x512", + "idiom" : "mac", + "filename" : "appIcon@2x.png", "scale" : "2x" } ], diff --git a/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/appIcon.png b/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/appIcon.png new file mode 100644 index 0000000..e5303a8 Binary files /dev/null and b/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/appIcon.png differ diff --git a/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/appIcon@2x.png b/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/appIcon@2x.png new file mode 100644 index 0000000..757f523 Binary files /dev/null and b/BrewServicesMenubar/Assets.xcassets/AppIcon.appiconset/appIcon@2x.png differ diff --git a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/Contents.json b/BrewServicesMenubar/Assets.xcassets/icon.imageset/Contents.json similarity index 73% rename from BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/Contents.json rename to BrewServicesMenubar/Assets.xcassets/icon.imageset/Contents.json index 3c81c9f..45b4497 100644 --- a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/Contents.json +++ b/BrewServicesMenubar/Assets.xcassets/icon.imageset/Contents.json @@ -2,17 +2,15 @@ "images" : [ { "idiom" : "universal", - "filename" : "icon.png", + "filename" : "icon.pdf", "scale" : "1x" }, { "idiom" : "universal", - "filename" : "icon@2x.png", "scale" : "2x" }, { "idiom" : "universal", - "filename" : "icon@3x.png", "scale" : "3x" } ], diff --git a/BrewServicesMenubar/Assets.xcassets/icon.imageset/icon.pdf b/BrewServicesMenubar/Assets.xcassets/icon.imageset/icon.pdf new file mode 100644 index 0000000..86bd4e1 Binary files /dev/null and b/BrewServicesMenubar/Assets.xcassets/icon.imageset/icon.pdf differ diff --git a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon.png b/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon.png deleted file mode 100644 index c659a68..0000000 Binary files a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon.png and /dev/null differ diff --git a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon@2x.png b/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon@2x.png deleted file mode 100644 index 712b2da..0000000 Binary files a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon@2x.png and /dev/null differ diff --git a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon@3x.png b/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon@3x.png deleted file mode 100644 index 736b79b..0000000 Binary files a/BrewServicesMenubar/Assets.xcassets/statusIcon.imageset/icon@3x.png and /dev/null differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a079de --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +brew-services-menubar +=== + +An OS X menu item for starting and stopping homebrew services Edit. + +This reads the [homebrew-services](https://github.com/Homebrew/homebrew-services) command + +![Screenshot](docs/screenshot.png) + +## Install + +1. Install [homebrew-services](https://github.com/Homebrew/homebrew-services) +2. Download from the [Releases](https://github.com/andrewn/brew-services-menubar/releases) page. + +## License + +Icon is [Beer by Enemen from the Noun Project](https://thenounproject.com/search/?q=beer&i=783212). diff --git a/assets/appIcon.png b/assets/appIcon.png new file mode 100644 index 0000000..e5303a8 Binary files /dev/null and b/assets/appIcon.png differ diff --git a/assets/appIcon@2x.png b/assets/appIcon@2x.png new file mode 100644 index 0000000..757f523 Binary files /dev/null and b/assets/appIcon@2x.png differ diff --git a/assets/icon.pdf b/assets/icon.pdf new file mode 100644 index 0000000..86bd4e1 Binary files /dev/null and b/assets/icon.pdf differ diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..3b51ff8 Binary files /dev/null and b/assets/icon.png differ diff --git a/assets/icon.sketch b/assets/icon.sketch new file mode 100644 index 0000000..0ee2f25 Binary files /dev/null and b/assets/icon.sketch differ diff --git a/assets/icon@2x.png b/assets/icon@2x.png new file mode 100644 index 0000000..44fb54b Binary files /dev/null and b/assets/icon@2x.png differ diff --git a/assets/icon@3x.png b/assets/icon@3x.png new file mode 100644 index 0000000..70ef9a5 Binary files /dev/null and b/assets/icon@3x.png differ diff --git a/assets/noun_783212_cc.svg b/assets/noun_783212_cc.svg new file mode 100644 index 0000000..d220145 --- /dev/null +++ b/assets/noun_783212_cc.svg @@ -0,0 +1,3 @@ +Created by Enemen from the Noun Project \ No newline at end of file diff --git a/docs/screenshot.png b/docs/screenshot.png new file mode 100644 index 0000000..c574bce Binary files /dev/null and b/docs/screenshot.png differ