punchnet-macos/punchnet/Views/Settings/SettingsSystemView.swift
2026-03-20 00:21:50 +08:00

111 lines
3.8 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.

//
// SettingsSystemView.swift
// punchnet
//
// Created by on 2026/1/19.
//
import SwiftUI
struct SettingsSystemView: View {
//
@State private var launchAtLogin: Bool = false
@State private var autoConnect: Bool = false
@State private var showMainUI: Bool = true
@State private var autoUpdate: Bool = true
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: 28) {
// MARK: -
systemSectionHeader(title: "启动与运行", icon: "power.circle.fill")
VStack(spacing: 0) {
ToggleRow(icon: "macwindow.badge.plus", title: "开机时自动启动", isOn: $launchAtLogin)
Divider().padding(.leading, 48) //
ToggleRow(icon: "bolt.horizontal.icloud.fill", title: "应用启动后自动连接", isOn: $autoConnect)
Divider().padding(.leading, 48)
ToggleRow(icon: "macwindow", title: "启动时显示主界面", isOn: $showMainUI)
}
.background(Color.primary.opacity(0.03))
.cornerRadius(12)
.overlay(RoundedRectangle(cornerRadius: 12).stroke(Color.primary.opacity(0.05), lineWidth: 1))
// MARK: -
systemSectionHeader(title: "软件更新", icon: "arrow.clockwise.circle.fill")
VStack(spacing: 0) {
ToggleRow(icon: "arrow.down.circle.fill", title: "自动下载并安装更新", isOn: $autoUpdate)
}
.background(Color.primary.opacity(0.03))
.cornerRadius(12)
.overlay(RoundedRectangle(cornerRadius: 12).stroke(Color.primary.opacity(0.05), lineWidth: 1))
// MARK: -
Text("当前版本1.0.4 (Build 202603) - 已是最新版本")
.font(.caption)
.foregroundColor(.secondary)
.padding(.horizontal, 4)
Spacer()
}
.padding(32)
.frame(maxWidth: 600, alignment: .leading)
}
}
//
private func systemSectionHeader(title: String, icon: String) -> some View {
HStack {
Image(systemName: icon)
.foregroundColor(.blue)
.font(.system(size: 14, weight: .semibold))
Text(title)
.font(.system(size: 15, weight: .bold))
.foregroundColor(.secondary)
}
.padding(.leading, 4)
}
}
// MARK: -
struct ToggleRow: View {
let icon: String
let title: String
@Binding var isOn: Bool
var body: some View {
HStack(spacing: 16) {
//
ZStack {
RoundedRectangle(cornerRadius: 6, style: .continuous)
.fill(Color.blue.opacity(0.1))
.frame(width: 28, height: 28)
Image(systemName: icon)
.font(.system(size: 14, weight: .medium))
.foregroundColor(.blue)
}
Text(title)
.font(.system(size: 14))
Spacer()
Toggle("", isOn: $isOn)
.toggleStyle(.switch) // 使 macOS
.labelsHidden() // Label 便
}
.padding(.horizontal, 16)
.padding(.vertical, 12)
}
}
#Preview {
SettingsSystemView()
}