Skip to content

Commit

Permalink
major rewrite
Browse files Browse the repository at this point in the history
 * update to swift 4
 * use Cartfile instead of cocoapods
 * instead of custom view use menu items
 * use docker command instead of docker-machine
 * add more docker options like start, stop, restart
 * rename witch to which, it's still a dumb name :)
 * use ReactiveTask for process management
  • Loading branch information
gschrader committed Oct 22, 2017
1 parent e361a5b commit 325969f
Show file tree
Hide file tree
Showing 33 changed files with 1,749 additions and 1,952 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Carthage
3 changes: 3 additions & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github "sindresorhus/LaunchAtLogin"
github "SwiftyJSON/SwiftyJSON"
github "Carthage/ReactiveTask"
5 changes: 5 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github "Carthage/ReactiveTask" "0.13.0"
github "ReactiveCocoa/ReactiveSwift" "2.0.1"
github "SwiftyJSON/SwiftyJSON" "3.1.4"
github "antitypical/Result" "3.2.4"
github "sindresorhus/LaunchAtLogin" "v2.0.0"
622 changes: 622 additions & 0 deletions Which Docker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
<true/>
<key>SnapshotAutomaticallyBeforeSignificantChanges</key>
<true/>
<key>SchemeUserState</key>
<dict>
<key>Which Docker.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
165 changes: 165 additions & 0 deletions Which Docker/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
//
// AppDelegate.swift
// Which Docker
//
// Created by Glen Schrader on 2017-10-08.
// Copyright © 2017 Glen Schrader. All rights reserved.
//

import Cocoa
import LaunchAtLogin


@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength)
var docker: Docker = Docker()

func applicationDidFinishLaunching(_ aNotification: Notification) {
if let button = statusItem.button {
button.image = NSImage(named:NSImage.Name("StatusBarButtonImage"))
button.action = #selector(reload(_:))
}
constructMenu()
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}

@IBAction func reload(_ sender: Any?) {
self.docker.findContainers()
constructMenu()
}

@objc func browse(_ sender: AnyObject) {
let port = sender.representedObject as! String
print( port)

if let url : URL = URL(string: "http://\(docker.ip):\(port)") {
NSWorkspace.shared.open(url)
}
}

@objc func startContainer(_ sender: AnyObject) {
let container = sender.representedObject as! Container
self.docker.startContainer(container)
constructMenu()
}

@objc func stopContainer(_ sender: AnyObject) {
let container = sender.representedObject as! Container
self.docker.stopContainer(container)
constructMenu()
}

@objc func execContainer(_ sender: AnyObject) {
let container = sender.representedObject as! Container
self.docker.exec(container)
}

@objc func restartContainer(_ sender: AnyObject) {
let container = sender.representedObject as! Container
self.docker.restartContainer(container)
constructMenu()
}

@objc func removeContainer(_ sender: AnyObject) {
let container = sender.representedObject as! Container
self.docker.removeContainer(container)
constructMenu()
}

@objc func showAbout(_ sender: NSMenuItem) {
NSApp.orderFrontStandardAboutPanel(sender);
}

@objc func launchToggle(_ sender: NSMenuItem) {
if sender.state == NSControl.StateValue.off {
LaunchAtLogin.isEnabled = false
} else {
LaunchAtLogin.isEnabled = true
}
print(LaunchAtLogin.isEnabled)
}

func constructMenu() {
let menu = NSMenu()

for container in docker.containers {
let containerMenu = NSMenu(title: "\(container.name)")

if (!container.running) {
let startMenuItem = NSMenuItem(title: "Start", action: #selector(AppDelegate.startContainer(_:)), keyEquivalent: "")
startMenuItem.representedObject = container
containerMenu.addItem(startMenuItem)
}

if (container.running) {
let restartMenuItem = NSMenuItem(title: "Restart", action: #selector(AppDelegate.restartContainer(_:)), keyEquivalent: "")
restartMenuItem.representedObject = container
containerMenu.addItem(restartMenuItem)

let stopMenuItem = NSMenuItem(title: "Stop", action: #selector(AppDelegate.stopContainer(_:)), keyEquivalent: "")
stopMenuItem.representedObject = container
containerMenu.addItem(stopMenuItem)

let execMenuItem = NSMenuItem(title: "Exec", action: #selector(AppDelegate.execContainer(_:)), keyEquivalent: "")
execMenuItem.representedObject = container
containerMenu.addItem(execMenuItem)
}

containerMenu.addItem(NSMenuItem.separator())

let removeMenuItem = NSMenuItem(title: "Remove", action: #selector(AppDelegate.removeContainer(_:)), keyEquivalent: "")
removeMenuItem.representedObject = container
containerMenu.addItem(removeMenuItem)

containerMenu.addItem(NSMenuItem.separator())

containerMenu.addItem(NSMenuItem(title: "Image: \(container.image)", action: nil, keyEquivalent: ""))

containerMenu.addItem(NSMenuItem.separator())

if (container.running) {
for port: String in container.ports {
let item = NSMenuItem(title: "Browse to \(port)", action: #selector(AppDelegate.browse(_:)), keyEquivalent: "")
item.representedObject = port
containerMenu.addItem(item)
}
}

let containerMenuItem = NSMenuItem(title: "\(container.name)", action: nil, keyEquivalent: "")

if (container.running) {
containerMenuItem.attributedTitle = NSAttributedString(string: "\(container.name)", attributes:[NSAttributedStringKey.font:NSFont.boldSystemFont(ofSize: 16)])
}

containerMenuItem.submenu = containerMenu
menu.addItem(containerMenuItem)
}

menu.addItem(NSMenuItem.separator())

menu.addItem(NSMenuItem(title: "Reload", action: #selector(AppDelegate.reload(_:)), keyEquivalent: "r"))

menu.addItem(NSMenuItem(title: "About Which Docker", action: #selector(AppDelegate.showAbout(_:)), keyEquivalent: ""))

let launchMenuItem = NSMenuItem.init(title: "Start Which Docker at Login", action: #selector(AppDelegate.launchToggle(_:)), keyEquivalent: "")
if LaunchAtLogin.isEnabled == true {
launchMenuItem.state = NSControl.StateValue.on
} else {
launchMenuItem.state = NSControl.StateValue.off
}
menu.addItem(launchMenuItem)

menu.addItem(NSMenuItem.separator())

menu.addItem(NSMenuItem(title: "Quit Which Docker", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))

statusItem.menu = menu
}

}

6 changes: 6 additions & 0 deletions Which Docker/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
Expand Up @@ -2,13 +2,13 @@
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "dockerx16.png"
"filename" : "dockerx16.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "dockerx32.png"
"filename" : "dockerx32.png",
"scale" : "2x"
},
{
"idiom" : "universal",
Expand All @@ -18,5 +18,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading

0 comments on commit 325969f

Please sign in to comment.