mirror of
https://github.com/neon443/RNG_Swift.git
synced 2026-03-11 06:49:12 +00:00
MACView: added a niiice reload button
This commit is contained in:
@@ -12,17 +12,41 @@ struct MACView: View {
|
|||||||
@State var mac: String = ""
|
@State var mac: String = ""
|
||||||
@State var maclook: String = ""
|
@State var maclook: String = ""
|
||||||
@State var looking: Bool = false
|
@State var looking: Bool = false
|
||||||
|
fileprivate func maclookup() async {
|
||||||
|
looking = true
|
||||||
|
maclook = await maclookupAPI(mac)
|
||||||
|
looking = false
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
HStack {
|
HStack {
|
||||||
Label("Vendor", systemImage: "building.2.fill")
|
Label("Vendor", systemImage: "building.2.fill")
|
||||||
Spacer()
|
Spacer()
|
||||||
if looking {
|
|
||||||
ProgressView()
|
|
||||||
} else {
|
|
||||||
Text(maclook)
|
Text(maclook)
|
||||||
.bold()
|
.bold()
|
||||||
|
.animation(.spring, value: looking)
|
||||||
|
.animation(.spring, value: maclook)
|
||||||
|
.contentTransition(.numericText())
|
||||||
|
Button() {
|
||||||
|
Task {
|
||||||
|
await maclookup()
|
||||||
}
|
}
|
||||||
|
} label: {
|
||||||
|
ZStack {
|
||||||
|
ProgressView()
|
||||||
|
.opacity(looking ? 1 : 0)
|
||||||
|
.animation(.spring, value: looking)
|
||||||
|
Image(systemName: "arrow.clockwise")
|
||||||
|
.resizable()
|
||||||
|
.scaledToFit()
|
||||||
|
.opacity(looking ? 0 : 1)
|
||||||
|
.animation(.spring, value: looking)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(width: 20)
|
||||||
|
.disabled(mac.isEmpty)
|
||||||
|
.buttonStyle(BorderlessButtonStyle())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +61,7 @@ struct MACView: View {
|
|||||||
mac = generateMAC()
|
mac = generateMAC()
|
||||||
}
|
}
|
||||||
Task {
|
Task {
|
||||||
looking = true
|
await maclookup()
|
||||||
maclook = await maclookup(mac)
|
|
||||||
looking = false
|
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
Text("Generate")
|
Text("Generate")
|
||||||
@@ -64,7 +86,7 @@ func generateMAC() -> String {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func maclookup(_ mac: String) async -> String {
|
func maclookupAPI(_ mac: String) async -> String {
|
||||||
let url = URL(string: "https://api.macvendors.com/\(mac)")!
|
let url = URL(string: "https://api.macvendors.com/\(mac)")!
|
||||||
var request = URLRequest(url: url)
|
var request = URLRequest(url: url)
|
||||||
request.httpMethod = "GET"
|
request.httpMethod = "GET"
|
||||||
|
|||||||
Reference in New Issue
Block a user