source: launchers/macosx/I2PLauncher/userinterface/RouterStatusView.swift @ 7a72049

Last change on this file since 7a72049 was 7a72049, checked in by meeh <meeh@…>, 21 months ago

Mac OS X Launcher:

  • Bugfixes as always
  • Added Sparkle (native updater, https://sparkle-project.org/ )
  • The launcher will now extract and overwrite older versions if found
  • Rewrite of the java extraction part (to enable overwrite)
  • Move more functionality to use EventManager? as it works quite well
  • Added check for updates menu item
  • Property mode set to 100644
File size: 3.7 KB
Line 
1//
2//  RouterStatusView.swift
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 22/09/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9import Cocoa
10
11@objc class RouterStatusView : NSView {
12  static var instance: RouterStatusView?
13 
14  static func getInstance() -> RouterStatusView? {
15    if (self.instance != Optional.none) {
16      return RouterStatusView.instance
17    }
18    return Optional.none
19  }
20 
21  @IBOutlet var routerStatusLabel: NSTextField?
22  @IBOutlet var routerVersionLabel: NSTextField?
23  @IBOutlet var routerStartedByLabel: NSTextField?
24  @IBOutlet var routerUptimeLabel: NSTextField?
25 
26  @IBOutlet var quickControlView: NSView?
27  @IBOutlet var routerStartStopButton: NSButton?
28 
29  @objc func actionBtnStartRouter(_ sender: Any?) {
30    NSLog("START ROUTER")
31    if (RouterManager.shared().getRouterTask() == nil) {
32      SBridge.sharedInstance().startupI2PRouter(RouterProcessStatus.i2pDirectoryPath, javaBinPath: RouterProcessStatus.knownJavaBinPath!)
33    }
34    RouterManager.shared().updateState()
35  }
36 
37  @objc func actionBtnStopRouter(_ sender: Any?) {
38    NSLog("STOP ROUTER")
39    if (RouterManager.shared().getRouterTask() != nil) {
40      NSLog("Found running router")
41      RouterManager.shared().getRouterTask()?.requestShutdown()
42      RouterManager.shared().updateState()
43    }
44  }
45 
46  @objc func actionBtnRestartRouter(sender: Any?) {
47    if (RouterManager.shared().getRouterTask() != nil) {
48      RouterManager.shared().getRouterTask()?.requestRestart()
49    } else {
50      NSLog("Can't restart a non running router, start it however...")
51      SBridge.sharedInstance().startupI2PRouter(RouterProcessStatus.i2pDirectoryPath, javaBinPath: RouterProcessStatus.knownJavaBinPath!)
52    }
53    RouterManager.shared().updateState()
54  }
55 
56 
57 
58  override func viewWillDraw() {
59    super.viewWillDraw()
60    if (RouterStatusView.instance != nil) {
61      RouterStatusView.instance = self
62    }
63    self.setRouterStatusLabelText()
64  }
65 
66  func setRouterStatusLabelText() {
67    if (RouterProcessStatus.isRouterRunning) {
68      routerStatusLabel?.cell?.stringValue = "Router status: Running"
69      routerStartStopButton?.title = "Stop Router"
70      routerStartStopButton?.action = #selector(self.actionBtnStopRouter(_:))
71    } else {
72      routerStatusLabel?.cell?.stringValue = "Router status: Not running"
73      routerStartStopButton?.title = "Start Router"
74      routerStartStopButton?.action = #selector(self.actionBtnStartRouter(_:))
75    }
76    routerStartStopButton?.needsDisplay = true
77    routerStartStopButton?.target = self
78    quickControlView?.needsDisplay = true
79   
80    let staticStartedByLabelText = "Router started by launcher?"
81    if RouterProcessStatus.isRouterChildProcess {
82      routerStartedByLabel?.cell?.stringValue = staticStartedByLabelText+" Yes"
83    } else {
84      routerStartedByLabel?.cell?.stringValue = staticStartedByLabelText+" No"
85    }
86    routerStartedByLabel?.needsDisplay = true
87   
88    if let version = RouterProcessStatus.routerVersion {
89      routerVersionLabel?.cell?.stringValue = "Router version: " + version
90    } else {
91      routerVersionLabel?.cell?.stringValue = "Router version: Still unknown"
92    }
93    if let routerStartTime = RouterProcessStatus.routerStartedAt {
94      routerUptimeLabel?.cell?.stringValue = "Uptime: Router started " + DateTimeUtils.timeAgoSinceDate(date: NSDate(date: routerStartTime), numericDates: false)
95    } else {
96      routerUptimeLabel?.cell?.stringValue = "Uptime: Router isn't running"
97    }
98    routerUptimeLabel?.needsDisplay = true
99  }
100 
101 
102  init() {
103    let c = NSCoder()
104    super.init(coder: c)!
105    self.setRouterStatusLabelText()
106  }
107 
108  required init?(coder decoder: NSCoder) {
109    super.init(coder: decoder)
110    self.setRouterStatusLabelText()
111  }
112 
113}
Note: See TracBrowser for help on using the repository browser.