forked from I2P_Developers/i2p.i2p
Adding all new code, removed a lot obsolete code and fixed import paths etc.
Mac OS X launcher: * UI built on Swift * Why? * Apple seems to on purpose make it harder to get into Objective-C these days * Swift is compiled to native code, but has easiness of Javascript in programming * Perfect for the OS X UI, many guides & tutorials as well * "Backend" in Objective-C++ / C++14 * Why? * Originally written in Objective-C / C++14 with C++17 backports * Only for backend because of the time the development takes * Short summary of features: * Java * It can detect java from: * JAVA_HOME environment variable * "Internet Plug-Ins" Apple stuff * By the /usr/libexec/java_home binary helper * It can unpack a new version of I2P * Unpacks to ~/Library/I2P * Can check currently unpacked version in ~/Library/I2P via i2p.jar's "net.i2p.CoreVersion" * User Interface (a popover, see https://youtu.be/k8L3lQ5rUq0 for example of this concept) * Router control tab view * It can start the router * It can stop the router * It can detect already running router, then avoid fireing up one * It can show basic information about the router state & version * Log view tab (not yet done) * While left-click triggers popover, right-click draws a minimal context menu
This commit is contained in:
@ -0,0 +1,118 @@
|
||||
//
|
||||
// PopoverViewController.swift
|
||||
// I2PLauncher
|
||||
//
|
||||
// Created by Mikal Villa on 18/09/2018.
|
||||
// Copyright © 2018 The I2P Project. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class PopoverViewController: NSViewController {
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
//super.init(nibName: "UserInterfaces", bundle: Bundle.main)!
|
||||
//let nib = NSNib(nibNamed: "UserInterfaces", bundle: Bundle.main)
|
||||
|
||||
}
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// Do view setup here.
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@objc class RouterStatusView : NSView {
|
||||
static var instance: RouterStatusView?
|
||||
|
||||
static func getInstance() -> RouterStatusView? {
|
||||
if (self.instance != Optional.none) {
|
||||
return RouterStatusView.instance
|
||||
}
|
||||
return Optional.none
|
||||
}
|
||||
|
||||
@IBOutlet var routerStatusLabel: NSTextField?
|
||||
@IBOutlet var routerVersionLabel: NSTextField?
|
||||
@IBOutlet var routerStartedByLabel: NSTextField?
|
||||
@IBOutlet var routerUptimeLabel: NSTextField?
|
||||
|
||||
@IBOutlet var quickControlView: NSView?
|
||||
@IBOutlet var routerStartStopButton: NSButton?
|
||||
|
||||
|
||||
@objc func actionBtnStartRouter(_ sender: Any?) {
|
||||
NSLog("START ROUTER")
|
||||
(sender as! NSButton).cell?.stringValue = "Stop Router"
|
||||
let timeWhenStarted = Date()
|
||||
RouterProcessStatus.routerStartedAt = timeWhenStarted
|
||||
SwiftMainDelegate.objCBridge.startupI2PRouter(RouterProcessStatus.i2pDirectoryPath, javaBinPath: RouterProcessStatus.knownJavaBinPath!)
|
||||
}
|
||||
@objc func actionBtnStopRouter(_ sender: Any?) {
|
||||
NSLog("STOP ROUTER")
|
||||
}
|
||||
@objc func actionBtnRestartRouter(sender: Any?) {}
|
||||
|
||||
override func viewWillDraw() {
|
||||
super.viewWillDraw()
|
||||
if (RouterStatusView.instance == Optional.none) {
|
||||
RouterStatusView.instance = self
|
||||
}
|
||||
self.setRouterStatusLabelText()
|
||||
}
|
||||
|
||||
func setRouterStatusLabelText() {
|
||||
if (RouterProcessStatus.isRouterRunning) {
|
||||
routerStatusLabel?.cell?.stringValue = "Router status: Running"
|
||||
routerStartStopButton?.action = #selector(self.actionBtnStopRouter(_:))
|
||||
} else {
|
||||
routerStatusLabel?.cell?.stringValue = "Router status: Not running"
|
||||
routerStartStopButton?.action = #selector(self.actionBtnStartRouter(_:))
|
||||
}
|
||||
routerStartStopButton?.needsDisplay = true
|
||||
routerStartStopButton?.target = self
|
||||
quickControlView?.needsDisplay = true
|
||||
|
||||
if (RouterProcessStatus.routerVersion?.isEmpty)! {
|
||||
routerVersionLabel?.cell?.stringValue = "Router version: Still unknown"
|
||||
} else {
|
||||
routerVersionLabel?.cell?.stringValue = "Router version: " + RouterProcessStatus.routerVersion!
|
||||
}
|
||||
if (RouterProcessStatus.routerStartedAt != Optional.none) {
|
||||
routerUptimeLabel?.cell?.stringValue = "Router has runned for " + DateTimeUtils.timeAgoSinceDate(date: NSDate(date: RouterProcessStatus.routerStartedAt!), numericDates: false)
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
let c = NSCoder()
|
||||
super.init(coder: c)!
|
||||
self.setRouterStatusLabelText()
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
super.init(coder: decoder)
|
||||
self.setRouterStatusLabelText()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extension PopoverViewController {
|
||||
static func freshController() -> PopoverViewController {
|
||||
let storyboard = NSStoryboard(name: "Storyboard", bundle: Bundle.main)
|
||||
//2.
|
||||
let identifier = NSStoryboard.SceneIdentifier(string: "PopoverView")
|
||||
//3.
|
||||
guard let viewcontroller = storyboard.instantiateController(withIdentifier: identifier as String) as? PopoverViewController else {
|
||||
fatalError("Why cant i find PopoverViewController? - Check PopoverViewController.storyboard")
|
||||
}
|
||||
//let viewcontroller = PopoverViewController()
|
||||
return viewcontroller
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user