-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
33 changed files
with
1,749 additions
and
1,952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Carthage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
github "sindresorhus/LaunchAtLogin" | ||
github "SwiftyJSON/SwiftyJSON" | ||
github "Carthage/ReactiveTask" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ject.xcworkspace/contents.xcworkspacedata → ...ject.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
Oops, something went wrong.