Skip to content

Commit

Permalink
Merge pull request #2 from andrewn/feature/new-icon
Browse files Browse the repository at this point in the history
New icon
  • Loading branch information
andrewn authored Jan 21, 2017
2 parents e7cc642 + 5ced62b commit 8375f53
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 28 deletions.
4 changes: 4 additions & 0 deletions BrewServicesMenubar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
TargetAttributes = {
49ED77AD1CD4B524000B4479 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -271,6 +274,7 @@
49ED77BD1CD4B525000B4479 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
47 changes: 24 additions & 23 deletions BrewServicesMenubar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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)
}

//
Expand All @@ -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)
}
Expand All @@ -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"
Expand All @@ -114,17 +115,17 @@ 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"
task.arguments = ["services", "list"]
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)
}

Expand All @@ -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..<rawServices.count].map(parseService)
}

func parseService(raw:String) -> Service {
func parseService(_ raw:String) -> Service {
let parts = matchesForRegexInText(matcher, text: raw)
let service = Service(name: parts[0], state: parts[1])
return service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "appIcon.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "[email protected]",
"scale" : "2x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"images" : [
{
"idiom" : "universal",
"filename" : "icon.png",
"filename" : "icon.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Binary file added assets/appIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon.pdf
Binary file not shown.
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon.sketch
Binary file not shown.
Binary file added assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/noun_783212_cc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8375f53

Please sign in to comment.