Updates for 0.5.x

This commit is contained in:
Neil Alexander 2024-06-23 11:36:26 +01:00
parent b58f8e3852
commit 838e37b928
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 89 additions and 110 deletions

View file

@ -68,17 +68,34 @@ class PeersViewController: UITableViewController {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "discoveredPeerPrototype", for: indexPath)
let peers = app.yggdrasilPeers.sorted { (a, b) -> Bool in
return (a["Port"] as! Int) < (b["Port"] as! Int)
return (a["URI"] as! String) < (b["URI"] as! String)
}
if indexPath.row < peers.count {
let value = peers[indexPath.row]
let up = value["Up"] as? Bool ?? false
let proto = value["Protocol"] as? String ?? "tcp"
let remote = value["Remote"] as? String ?? "unknown"
let prio = value["Priority"] as? Int ?? 0
let uri = value["URI"] as? String ?? "unknown"
let uptime = value["Uptime"] as? UInt64 ?? 0
cell.textLabel?.text = "\(value["IP"] ?? "(unknown)")"
cell.detailTextLabel?.text = "\(proto.uppercased()): \(remote)"
if !up {
cell.textLabel?.text = uri
cell.detailTextLabel?.text = "Not connected"
cell.textLabel?.textColor = .systemGray
cell.detailTextLabel?.textColor = .systemGray
} else {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute, .second]
formatter.unitsStyle = .short
let uptime = formatter.string(from: TimeInterval(uptime / 1000 / 1000 / 1000))!
cell.textLabel?.text = uri
cell.detailTextLabel?.text = "Connected via \(proto.uppercased()), uptime \(uptime)"
cell.textLabel?.textColor = .label
cell.detailTextLabel?.textColor = .label
}
}
return cell
case 1:
@ -167,18 +184,11 @@ class PeersViewController: UITableViewController {
switch section {
case 0:
if self.app.yggdrasilPeers.count > 0 {
return "Connected Peers"
return "Peer Status"
}
return "No peers currently connected"
return "No Configured Peers"
case 1:
if let config = self.app.yggdrasilConfig {
if let peers = config.get("Peers") as? [String] {
if peers.count > 0 {
return "Configured Peers"
}
}
}
return "No peers currently configured"
return "Configured Peers"
case 2:
return "Peer Connectivity"
default: return "(Unknown)"

View file

@ -13,11 +13,9 @@ class TableViewController: UITableViewController {
@IBOutlet weak var statsSelfIPCell: UITableViewCell!
@IBOutlet weak var statsSelfSubnetCell: UITableViewCell!
@IBOutlet weak var statsSelfCoordsCell: UITableViewCell!
@IBOutlet var statsSelfIP: UILabel!
@IBOutlet var statsSelfSubnet: UILabel!
@IBOutlet var statsSelfCoords: UILabel!
@IBOutlet var statsSelfPeers: UILabel!
@IBOutlet var statsVersion: UILabel!
@ -25,7 +23,6 @@ class TableViewController: UITableViewController {
override func viewDidLoad() {
NotificationCenter.default.addObserver(self, selector: #selector(self.onYggdrasilSelfUpdated), name: NSNotification.Name.YggdrasilSelfUpdated, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.onYggdrasilPeersUpdated), name: NSNotification.Name.YggdrasilPeersUpdated, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.onYggdrasilDHTUpdated), name: NSNotification.Name.YggdrasilDHTUpdated, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.onYggdrasilSettingsUpdated), name: NSNotification.Name.YggdrasilSettingsUpdated, object: nil)
}
@ -76,7 +73,7 @@ class TableViewController: UITableViewController {
func updateConnectedStatus() {
if self.app.vpnManager.connection.status == .connected {
if app.yggdrasilDHT.count > 0 {
if app.yggdrasilPeers.count > 0 {
connectedStatusLabel.text = "Enabled"
connectedStatusLabel.textColor = UIColor(red: 0.37, green: 0.79, blue: 0.35, alpha: 1.0)
} else {
@ -96,11 +93,9 @@ class TableViewController: UITableViewController {
@objc func onYggdrasilSelfUpdated(notification: NSNotification) {
statsSelfIP.text = app.yggdrasilSelfIP
statsSelfSubnet.text = app.yggdrasilSelfSubnet
statsSelfCoords.text = app.yggdrasilSelfCoords
statsSelfIPCell.layoutSubviews()
statsSelfSubnetCell.layoutSubviews()
statsSelfCoordsCell.layoutSubviews()
let status = self.app.vpnManager.connection.status
toggleConnect.isOn = status == .connecting || status == .connected
@ -113,7 +108,7 @@ class TableViewController: UITableViewController {
}
@objc func onYggdrasilPeersUpdated(notification: NSNotification) {
let peercount = app.yggdrasilPeers.count
let peercount = app.yggdrasilPeers.filter { $0["Up"] as? Bool ?? false }.count
if peercount <= 0 {
statsSelfPeers.text = "No peers"
} else if peercount == 1 {