Reformat code

This commit is contained in:
世界
2026-02-08 18:23:42 +08:00
parent f765bf1e3b
commit a86dfc26d1
42 changed files with 163 additions and 98 deletions
@@ -3,7 +3,6 @@ import Library
import SwiftUI
public extension View {
@ViewBuilder
func alert(_ binding: Binding<AlertState?>, isLoading: Binding<Bool>) -> some View {
alert(
binding.wrappedValue?.title ?? "",
@@ -1,7 +1,7 @@
import Foundation
import SwiftUI
public struct DeleteButton<Label>: View where Label: View {
public struct DeleteButton<Label: View>: View {
private let action: () async -> Void
private let label: Label
@@ -8,7 +8,7 @@ import SwiftUI
#endif
@MainActor
public struct ProfileShareButton<Label>: View where Label: View {
public struct ProfileShareButton<Label: View>: View {
private let alert: Binding<AlertState?>
private let profile: Profile
private let label: () -> Label
@@ -40,7 +40,7 @@ public struct ProfileShareButton<Label>: View where Label: View {
}
}
public struct ShareButtonCompat<Label>: View where Label: View {
public struct ShareButtonCompat<Label: View>: View {
private let label: () -> Label
private let itemURL: () async throws -> URL
@@ -137,8 +137,7 @@ public struct ShareButtonCompat<Label>: View where Label: View {
}
func makeNSView(context _: Context) -> NSView {
let view = NSView()
return view
NSView()
}
func updateNSView(_ nsView: NSView, context: Context) {
@@ -7,7 +7,7 @@ public extension View {
}
}
func onChangeCompat<V>(of value: V, _ action: @escaping (_ newValue: V) -> Void) -> some View where V: Equatable {
func onChangeCompat<V: Equatable>(of value: V, _ action: @escaping (_ newValue: V) -> Void) -> some View {
onChange(of: value, perform: action)
}
}
@@ -147,7 +147,6 @@ public extension View {
#endif
public extension View {
@ViewBuilder
func cardStyle() -> some View {
modifier(CardStyleModifier())
}
@@ -152,7 +152,7 @@ import SwiftUI
#endif
}
@ViewBuilder private var overviewPage: some View {
private var overviewPage: some View {
OverviewView(
$coordinator.profileList,
$coordinator.selectedProfileID,
@@ -10,7 +10,9 @@ public enum DashboardCard: String, CaseIterable, Identifiable, Codable, Hashable
case clashMode
case profile
public var id: String { rawValue }
public var id: String {
rawValue
}
public var title: LocalizedStringKey {
switch self {
@@ -188,7 +188,6 @@ public struct ProfileCard: View {
#endif
}
@ViewBuilder
private func actionButtonsRow(for profile: ProfilePreview) -> some View {
HStack(spacing: actionButtonSpacing) {
editButton(for: profile)
@@ -201,7 +200,6 @@ public struct ProfileCard: View {
}
}
@ViewBuilder
private func editButton(for profile: ProfilePreview) -> some View {
Button {
viewModel.profileToEdit = profile.origin
@@ -213,7 +211,6 @@ public struct ProfileCard: View {
.actionButtonStyle()
}
@ViewBuilder
private func updateButton(for profile: ProfilePreview) -> some View {
Button {
viewModel.isUpdating = true
@@ -436,7 +433,6 @@ public struct ProfileCard: View {
}
}
@ViewBuilder
private func profileInfo(for profile: ProfilePreview) -> some View {
HStack(spacing: 8) {
HStack(spacing: 4) {
@@ -437,7 +437,6 @@ struct ProfilePickerSheet: View {
}
#if os(macOS)
@ViewBuilder
private func macOSProfileRow(_ profile: ProfilePreview) -> some View {
ProfilePickerRow(
profile: profile,
@@ -928,7 +927,6 @@ private struct ProfilePickerRow: View {
}
#if !os(tvOS)
@ViewBuilder
private var shareMenu: some View {
Menu {
#if os(macOS)
@@ -1345,7 +1343,6 @@ private struct ProfilePickerRow: View {
}
}
@ViewBuilder
private var shareMenu: some View {
Menu {
Button {
@@ -103,7 +103,7 @@ public struct ExtensionStatusView: View {
}
}
private struct StatusItem<T>: View where T: View {
private struct StatusItem<T: View>: View {
@Environment(\.colorScheme) private var colorScheme
private let title: String
@@ -48,7 +48,6 @@ public struct DashboardView: View {
#endif
}
@ViewBuilder
private func importRemoteProfileSheet(for request: ImportRemoteProfileRequest) -> some View {
NavigationSheet(title: "Import Profile", onDismiss: {
environments.profileUpdate.send()
@@ -99,7 +98,6 @@ public struct DashboardView: View {
}
}
@ViewBuilder
private var activeDashboardView: some View {
ActiveDashboardView(coordinator: coordinator)
}
+4 -4
View File
@@ -272,7 +272,6 @@ private struct LogContentInnerView: View {
#endif
}
@ViewBuilder
private var emptyContent: some View {
Group {
if dataModel.isConnected {
@@ -427,7 +426,9 @@ private struct LogContentInnerView: View {
}
private struct LogTextDocument: FileDocument {
static var readableContentTypes: [UTType] { [.plainText] }
static var readableContentTypes: [UTType] {
[.plainText]
}
private let url: URL
@@ -466,8 +467,7 @@ private struct LogContentInnerView: View {
@Binding var alert: AlertState?
func makeNSView(context _: Context) -> NSView {
let view = NSView()
return view
NSView()
}
func updateNSView(_ nsView: NSView, context _: Context) {
@@ -25,8 +25,13 @@ public class LogDataModel: ObservableObject {
private static let maxVisibleLogs = 1000
public var isEmpty: Bool { commandClient.logList.isEmpty }
public var isConnected: Bool { commandClient.isConnected }
public var isEmpty: Bool {
commandClient.logList.isEmpty
}
public var isConnected: Bool {
commandClient.isConnected
}
private func updateVisibleLogs() {
if filteredLogs.count <= Self.maxVisibleLogs {
@@ -28,8 +28,8 @@
}
DevicePicker(
.applicationService(name: "sing-box:profile"))
{ endpoint in
.applicationService(name: "sing-box:profile")
) { endpoint in
viewModel.selected = true
Task {
await viewModel.handleEndpoint(endpoint, environments: environments)
@@ -11,13 +11,19 @@ public struct NewProfileView: View {
private var onSuccess: ((Profile) async -> Void)?
public struct ImportRequest: Codable, Hashable, Identifiable {
public var id: String { url }
public var id: String {
url
}
public let name: String
public let url: String
}
public struct LocalImportRequest: Hashable, Identifiable {
public var id: String { fileURL.absoluteString }
public var id: String {
fileURL.absoluteString
}
public let name: String
public let fileURL: URL
@@ -242,8 +242,7 @@
let controller: QRScannerController
func makeUIViewController(context _: Context) -> UIViewController {
let viewController = QRScannerViewController(controller: controller)
return viewController
QRScannerViewController(controller: controller)
}
func updateUIViewController(_: UIViewController, context _: Context) {}
@@ -247,8 +247,7 @@
let controller: QRScannerController
func makeNSViewController(context _: Context) -> NSViewController {
let viewController = QRScannerViewController(controller: controller)
return viewController
QRScannerViewController(controller: controller)
}
func updateNSViewController(_: NSViewController, context _: Context) {}
@@ -7,7 +7,9 @@ private enum OnDemandMode: String, CaseIterable, Identifiable {
case alwaysOn
case enabled
var id: String { rawValue }
var id: String {
rawValue
}
var name: String {
switch self {
@@ -114,7 +116,6 @@ public struct OnDemandRulesView: View {
}
}
@ViewBuilder
private var rulesSection: some View {
Section {
if rules.isEmpty {
@@ -463,7 +464,6 @@ private struct OnDemandRuleEditView: View {
#endif
}
@ViewBuilder
private var connectionRulesSection: some View {
Section {
if rule.connectionRules.isEmpty {
@@ -128,7 +128,6 @@ public struct SettingView: View {
#if os(macOS)
@MainActor
@ViewBuilder
private static func destinationView(for page: SettingsPage) -> some View {
Group {
switch page {