source: launchers/macosx/I2PLauncher/userinterface/PopoverViewController.swift @ 3c0a8cf

Last change on this file since 3c0a8cf was 3c0a8cf, checked in by meeh <meeh@…>, 23 months ago

Mac OSX Launcher: A lot of bugfixes, refactoring and cleanup.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1//
2//  PopoverViewController.swift
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 18/09/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9import Cocoa
10
11class PopoverViewController: NSViewController {
12 
13  required init?(coder: NSCoder) {
14    super.init(coder: coder)
15    //super.init(nibName: "UserInterfaces", bundle: Bundle.main)!
16    //let nib = NSNib(nibNamed: "UserInterfaces", bundle: Bundle.main)
17   
18  }
19 
20 
21  override func viewDidLoad() {
22    super.viewDidLoad()
23    // Do view setup here.
24  }
25 
26 
27 
28}
29
30@objc class RouterStatusView : NSView {
31  static var instance: RouterStatusView?
32 
33  static func getInstance() -> RouterStatusView? {
34    if (self.instance != Optional.none) {
35      return RouterStatusView.instance
36    }
37    return Optional.none
38  }
39 
40  @IBOutlet var routerStatusLabel: NSTextField?
41  @IBOutlet var routerVersionLabel: NSTextField?
42  @IBOutlet var routerStartedByLabel: NSTextField?
43  @IBOutlet var routerUptimeLabel: NSTextField?
44 
45  @IBOutlet var quickControlView: NSView?
46  @IBOutlet var routerStartStopButton: NSButton?
47 
48 
49  @objc func actionBtnStartRouter(_ sender: Any?) {
50    NSLog("START ROUTER")
51    (sender as! NSButton).cell?.stringValue = "Stop Router"
52    let timeWhenStarted = Date()
53    RouterProcessStatus.routerStartedAt = timeWhenStarted
54    SwiftMainDelegate.objCBridge.startupI2PRouter(RouterProcessStatus.i2pDirectoryPath, javaBinPath: RouterProcessStatus.knownJavaBinPath!)
55  }
56  @objc func actionBtnStopRouter(_ sender: Any?) {
57    NSLog("STOP ROUTER")
58  }
59  @objc func actionBtnRestartRouter(sender: Any?) {}
60 
61  override func viewWillDraw() {
62    super.viewWillDraw()
63    if (RouterStatusView.instance != nil) {
64      RouterStatusView.instance = self
65    }
66    self.setRouterStatusLabelText()
67  }
68 
69  func setRouterStatusLabelText() {
70    if (RouterProcessStatus.isRouterRunning) {
71      routerStatusLabel?.cell?.stringValue = "Router status: Running"
72      routerStartStopButton?.action = #selector(self.actionBtnStopRouter(_:))
73    } else {
74      routerStatusLabel?.cell?.stringValue = "Router status: Not running"
75      routerStartStopButton?.action = #selector(self.actionBtnStartRouter(_:))
76    }
77    routerStartStopButton?.needsDisplay = true
78    routerStartStopButton?.target = self
79    quickControlView?.needsDisplay = true
80   
81    if let version = RouterProcessStatus.routerVersion {
82      routerVersionLabel?.cell?.stringValue = "Router version: " + version
83    } else {
84      routerVersionLabel?.cell?.stringValue = "Router version: Still unknown"
85    }
86    if let routerStartTime = RouterProcessStatus.routerStartedAt {
87      routerUptimeLabel?.cell?.stringValue = "Router has runned for " + DateTimeUtils.timeAgoSinceDate(date: NSDate(date: routerStartTime), numericDates: false)
88    }
89  }
90 
91  init() {
92    let c = NSCoder()
93    super.init(coder: c)!
94    self.setRouterStatusLabelText()
95  }
96 
97  required init?(coder decoder: NSCoder) {
98    super.init(coder: decoder)
99    self.setRouterStatusLabelText()
100  }
101 
102}
103
104
105extension PopoverViewController {
106  static func freshController() -> PopoverViewController {
107    let storyboard = NSStoryboard(name: "Storyboard", bundle: Bundle.main)
108    //2.
109    let identifier = NSStoryboard.SceneIdentifier(stringLiteral: "PopoverView")
110    //3.
111    guard let viewcontroller = storyboard.instantiateController(withIdentifier: identifier as String) as? PopoverViewController else {
112      fatalError("Why cant i find PopoverViewController? - Check PopoverViewController.storyboard")
113    }
114    //let viewcontroller = PopoverViewController()
115    return viewcontroller
116  }
117}
118
Note: See TracBrowser for help on using the repository browser.