punchnet-macos/punchnet/Views/Settings/SettingsDeviceView.swift

124 lines
4.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SettingsDeviceView.swift
// punchnet
//
// Created by on 2026/1/19.
//
import SwiftUI
struct SettingsDeviceView: View {
@Environment(AppContext.self) var appContext: AppContext
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: 28) {
// MARK: -
HStack(spacing: 16) {
Image(systemName: "laptopcomputer")
.font(.system(size: 36))
.foregroundStyle(.blue.gradient)
.frame(width: 60, height: 60)
.background(Color.blue.opacity(0.1))
.cornerRadius(12)
// TODO
// VStack(alignment: .leading, spacing: 4) {
// Text(self.appContext.networkContext?.hostname ?? "")
// .font(.title3.bold())
//
// Text(SystemConfig.systemInfo)
// .font(.subheadline)
// .foregroundColor(.secondary)
// }
}
.padding(.horizontal, 4)
// MARK: -
VStack(alignment: .leading, spacing: 0) {
//
DevicePropertyRow(title: "设备名称", value: self.appContext.networkContext?.hostname ?? "未定义") {
Button {
//
} label: {
Text("修改")
.font(.subheadline.bold())
.padding(.horizontal, 12)
.padding(.vertical, 4)
.background(Capsule().fill(Color.blue.opacity(0.1)))
.foregroundColor(.blue)
}
.buttonStyle(.plain)
}
Divider().padding(.leading, 16)
// IPv4
DevicePropertyRow(title: "虚拟 IPv4", value: self.appContext.networkContext?.ip ?? "0.0.0.0") {
Image(systemName: "info.circle")
.foregroundColor(.secondary)
}
Divider().padding(.leading, 16)
// // IPv6
// DevicePropertyRow(title: " IPv6", value: "fe80::ab:ef:1") {
// Text("")
// .font(.caption2.bold())
// .padding(.horizontal, 6)
// .padding(.vertical, 2)
// .background(Color.green.opacity(0.1))
// .foregroundColor(.green)
// .cornerRadius(4)
// }
}
.background(Color.primary.opacity(0.03))
.cornerRadius(12)
.overlay(RoundedRectangle(cornerRadius: 12).stroke(Color.primary.opacity(0.05), lineWidth: 1))
// MARK: -
Text("此设备在虚拟网络中是唯一的,修改名称不会影响连接标识。")
.font(.caption)
.foregroundColor(.secondary)
.padding(.horizontal, 4)
Spacer()
}
.padding(32)
.frame(maxWidth: 600, alignment: .leading)
}
}
}
// MARK: -
struct DevicePropertyRow<Content: View>: View {
let title: String
let value: String
let trailingContent: () -> Content
init(title: String, value: String, @ViewBuilder trailingContent: @escaping () -> Content) {
self.title = title
self.value = value
self.trailingContent = trailingContent
}
var body: some View {
HStack {
Text(title)
.foregroundColor(.secondary)
.frame(width: 100, alignment: .leading)
Text(value)
.fontWeight(.medium)
.font(.system(.body, design: .monospaced)) // 使 IP
Spacer()
trailingContent()
}
.padding(.horizontal, 16)
.padding(.vertical, 14)
}
}