refactored code structure
This commit is contained in:
127
Sources/Views/Tabs/GeneralView.swift
Normal file
127
Sources/Views/Tabs/GeneralView.swift
Normal file
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// GeneralTab.swift
|
||||
// iKeyMon
|
||||
//
|
||||
// Created by tracer on 30.03.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct GeneralView: View {
|
||||
@Binding var server: Server
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
TableRowView {
|
||||
Text("Hostname")
|
||||
} value: {
|
||||
InfoCell(value: [server.hostname])
|
||||
}
|
||||
|
||||
TableRowView {
|
||||
Text("IP addresses")
|
||||
} value: {
|
||||
InfoCell(value: server.info?.ipAddresses ?? [], monospaced: true)
|
||||
}
|
||||
|
||||
TableRowView {
|
||||
Text("Server time")
|
||||
} value: {
|
||||
InfoCell(value: [server.info?.formattedServerTime ?? ""], monospaced: true)
|
||||
}
|
||||
|
||||
TableRowView {
|
||||
Text("Uptime")
|
||||
} value: {
|
||||
InfoCell(value: [server.info?.uptime ?? ""])
|
||||
}
|
||||
|
||||
TableRowView {
|
||||
Text("KeyHelp version")
|
||||
} value: {
|
||||
InfoCell(value: [server.info?.formattedVersion ?? ""], monospaced: true)
|
||||
}
|
||||
|
||||
TableRowView {
|
||||
Text("Operating system")
|
||||
} value: {
|
||||
InfoCell(
|
||||
value: {
|
||||
guard let os = server.info?.operatingSystem else { return [] }
|
||||
var rows: [String] = []
|
||||
|
||||
let distro = [os.distribution, os.version]
|
||||
.filter { !$0.isEmpty }
|
||||
.joined(separator: " ")
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
var description = os.label.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if description.isEmpty {
|
||||
description = distro
|
||||
} else if !distro.isEmpty && distro.caseInsensitiveCompare(description) != .orderedSame {
|
||||
description += " • \(distro)"
|
||||
}
|
||||
if !os.architecture.isEmpty {
|
||||
description += " (\(os.architecture))"
|
||||
}
|
||||
if !description.isEmpty {
|
||||
rows.append(description)
|
||||
}
|
||||
|
||||
if let updates = os.updates {
|
||||
var updateDescription = "Updates: \(updates.updateCount)"
|
||||
if updates.securityUpdateCount > 0 {
|
||||
updateDescription += " • \(updates.securityUpdateCount) security"
|
||||
}
|
||||
rows.append(updateDescription)
|
||||
if updates.rebootRequired {
|
||||
rows.append("Reboot required")
|
||||
}
|
||||
}
|
||||
|
||||
if os.endOfLife {
|
||||
rows.append("End-of-life release")
|
||||
}
|
||||
|
||||
return rows
|
||||
}(),
|
||||
monospaced: true
|
||||
)
|
||||
}
|
||||
|
||||
TableRowView {
|
||||
Text("Sytem PHP version")
|
||||
} value: {
|
||||
InfoCell(value: [server.info?.phpVersion ?? ""], monospaced: true)
|
||||
}
|
||||
|
||||
TableRowView(showDivider: false) {
|
||||
Text("Additional PHP interpreters")
|
||||
} value: {
|
||||
InfoCell(
|
||||
value: server.info?.additionalPHPInterpreters?.map { $0.versionFull } ?? [],
|
||||
monospaced: true
|
||||
)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minHeight: geometry.size.height, alignment: .top)
|
||||
}
|
||||
.padding()
|
||||
.scrollDisabled(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
struct PreviewWrapper: View {
|
||||
@State var previewServer = Server(hostname: "example.com", info: .placeholder)
|
||||
|
||||
var body: some View {
|
||||
GeneralView(server: $previewServer)
|
||||
}
|
||||
}
|
||||
|
||||
return PreviewWrapper()
|
||||
}
|
||||
Reference in New Issue
Block a user