Skip to content

Commit

Permalink
Merge pull request #1 from Lustres/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lustres committed Aug 10, 2017
2 parents f2d95b5 + 26cd395 commit 8e78d6e
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 87 deletions.
8 changes: 4 additions & 4 deletions homebrew-services.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

/* Begin PBXBuildFile section */
027D4DE11F3B1FF500602020 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027D4DE01F3B1FF500602020 /* AppDelegate.swift */; };
027D4DE31F3B1FF500602020 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027D4DE21F3B1FF500602020 /* ViewController.swift */; };
027D4DE51F3B1FF500602020 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 027D4DE41F3B1FF500602020 /* Assets.xcassets */; };
027D4DE81F3B1FF500602020 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 027D4DE61F3B1FF500602020 /* Main.storyboard */; };
027D4DF11F3B290600602020 /* Service.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027D4DF01F3B290600602020 /* Service.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
027D4DDD1F3B1FF500602020 /* homebrew-services.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "homebrew-services.app"; sourceTree = BUILT_PRODUCTS_DIR; };
027D4DE01F3B1FF500602020 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
027D4DE21F3B1FF500602020 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
027D4DE41F3B1FF500602020 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
027D4DE71F3B1FF500602020 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
027D4DE91F3B1FF500602020 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
027D4DEA1F3B1FF500602020 /* homebrew_services.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = homebrew_services.entitlements; sourceTree = "<group>"; };
027D4DF01F3B290600602020 /* Service.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Service.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -54,7 +54,7 @@
isa = PBXGroup;
children = (
027D4DE01F3B1FF500602020 /* AppDelegate.swift */,
027D4DE21F3B1FF500602020 /* ViewController.swift */,
027D4DF01F3B290600602020 /* Service.swift */,
027D4DE41F3B1FF500602020 /* Assets.xcassets */,
027D4DE61F3B1FF500602020 /* Main.storyboard */,
027D4DE91F3B1FF500602020 /* Info.plist */,
Expand Down Expand Up @@ -133,8 +133,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
027D4DE31F3B1FF500602020 /* ViewController.swift in Sources */,
027D4DE11F3B1FF500602020 /* AppDelegate.swift in Sources */,
027D4DF11F3B290600602020 /* Service.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
114 changes: 110 additions & 4 deletions homebrew-services/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,122 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

let statusBarItem = NSStatusBar.system.statusItem(withLength: -2)


let services = Services.sharedInstance

private var notifyToken: Any?

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
statusBarItem.menu = NSMenu()

statusBarItem.button?.image = #imageLiteral(resourceName: "StatusBarButtonIcon")

notifyToken = NotificationCenter.default
.addObserver(forName: NSNotification.Name(rawValue: "NSMenuDidBeginTrackingNotification"),
object: nil,
queue: nil) {[unowned self] _ in self.fresh()}

fresh()
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
deinit {
NotificationCenter.default.removeObserver(notifyToken!)
}
}

extension AppDelegate {
@objc func fresh() {

DispatchQueue.global(qos: .userInteractive).async {
[unowned self] in

var dict = self.services.list()

DispatchQueue.main.sync {
[unowned self] in
let menu = self.statusBarItem.menu!

for item in menu.items {

if let s = dict[item.title] {
if state(s) != item.state {
item.state = state(s)
}
dict.removeValue(forKey: item.title)
} else {
menu.removeItem(item)
}
}

for(serviceName, state) in dict {
let item = NSMenuItem(title: serviceName,
action: #selector(AppDelegate.toggole),
keyEquivalent: "String")

if state {
item.state = .onState
}

menu.addItem(item)
}
} // main queue
} // global queue

}


@objc func toggole(_ sender: NSMenuItem!) {
debugPrint("[toggole]: \(sender.title) - \(sender.state)")
sender.action = nil
DispatchQueue.global(qos: .userInteractive).async {
[unowned self] in

var actionName = ""
var r = false

switch sender.state {
case .offState:
actionName = "Start"
r = self.services.start(sender.title)

case .onState:
actionName = "Stop"
r = self.services.stop(sender.title)

default:
break
}


let post = (r ? succPost : failPost)(actionName, sender.title)

DispatchQueue.main.async {
NSUserNotificationCenter.default.deliver(post)
}

self.fresh()

DispatchQueue.main.sync {
sender.action = #selector(AppDelegate.toggole)
}
}
}
}

fileprivate func succPost(action: String, name: String) -> NSUserNotification {
let post = NSUserNotification()
post.title = "\(action) \(name) Succeeded"
return post;
}

fileprivate func failPost(action: String, name: String) -> NSUserNotification {
let post = NSUserNotification()
post.title = "\(action) \(name) Failed"
post.soundName = "Funk"
return post;
}

fileprivate func state(_ s: Bool) -> NSControl.StateValue {
return s ? .onState : .offState
}
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.
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.
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.
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.
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.
30 changes: 20 additions & 10 deletions homebrew-services/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,63 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "BeerService-9.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "BeerService-8.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "BeerService-7.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "BeerService-6.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "BeerService-5.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "BeerService-4.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "BeerService-3.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "BeerService-2.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "BeerService-1.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "BeerService.png",
"scale" : "2x"
}
],
Expand Down
6 changes: 6 additions & 0 deletions homebrew-services/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "baricon-1.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "baricon.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
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.
43 changes: 5 additions & 38 deletions homebrew-services/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13168.3" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13168.3"/>
</dependencies>
<scenes>
<!--Application-->
Expand Down Expand Up @@ -673,45 +674,11 @@
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="homebrew_services" customModuleProvider="target"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="0.0"/>
</scene>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<connections>
<outlet property="delegate" destination="B8D-0N-5wS" id="98r-iN-zZc"/>
</connections>
</window>
<connections>
<segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/>
</connections>
</windowController>
<customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="250"/>
</scene>
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="655"/>
</scene>
</scenes>
</document>
2 changes: 2 additions & 0 deletions homebrew-services/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSUIElement</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
Loading

0 comments on commit 8e78d6e

Please sign in to comment.