From b49957d54c1069f014b6b51fd6dea846236fcc91 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 28 Apr 2025 19:57:03 +0100 Subject: [PATCH] fix vendor lookup minor ui --- RNG/IPView.swift | 8 ++++++-- RNG/MACView.swift | 37 ++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/RNG/IPView.swift b/RNG/IPView.swift index 825f278..fa2e8de 100644 --- a/RNG/IPView.swift +++ b/RNG/IPView.swift @@ -17,9 +17,13 @@ struct IPView: View { Text("IPv6").tag(6) } .pickerStyle(SegmentedPickerStyle()) - Text(ip) - .contentTransition(.numericText()) } + Text(ip) + .font(.system(size: 30)) + .foregroundColor(.gray) + .frame(height: 40) + .contentTransition(.numericText()) + .monospaced() Button { withAnimation { ip = generateIPv(ipType) diff --git a/RNG/MACView.swift b/RNG/MACView.swift index 5fad525..a5fea7b 100644 --- a/RNG/MACView.swift +++ b/RNG/MACView.swift @@ -11,20 +11,18 @@ import SwiftUI struct MACView: View { @State var mac: String = "" @State var maclook: String = "" + @State var looking: Bool = false var body: some View { - Button("test") { - mac = "1c:57:dc:7f:d4:ce" - Task { - maclook = await maclookup(mac) - } - } - List { HStack { Label("Vendor", systemImage: "building.2.fill") Spacer() - Text(maclook) - .bold() + if looking { + ProgressView() + } else { + Text(maclook) + .bold() + } } } @@ -39,7 +37,9 @@ struct MACView: View { mac = generateMAC() } Task { + looking = true maclook = await maclookup(mac) + looking = false } } label: { Text("Generate") @@ -55,11 +55,11 @@ struct MACView: View { func generateMAC() -> String { var output = "" - for _ in 0..<6 { - output.append(hex(Int.random(in: 0...15)).hex) - output.append(hex(rng(min: 0, max: 15)).hex) - output.append(":") - } + for _ in 0..<6 { + output.append(hex(Int.random(in: 0...15)).hex) + output.append(hex(rng(min: 0, max: 15)).hex) + output.append(":") + } output.removeLast() return output } @@ -74,12 +74,11 @@ func maclookup(_ mac: String) async -> String { let result = String(data: data, encoding: .utf8) ?? "Lookup Error" if result.contains("{") { let dict = try JSONDecoder().decode([String: [String: String]].self, from: data) - if let dict = dict["error"] { - print(dict["detail"] as Any) + if let dict = dict["errors"] { + return "\(dict["detail"]!)" } } - - return "sd" + return result } catch { print(error.localizedDescription) return "Lookup Error" @@ -118,5 +117,5 @@ class hex { } } #Preview { - MACView() + MACView() }