Add swiftlint & Minor fixes
This commit is contained in:
@@ -4,11 +4,8 @@ import SwiftUI
|
||||
@MainActor public struct CardManagementSheet: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@StateObject private var configuration = DashboardCardConfiguration()
|
||||
@Binding private var configurationVersion: Int
|
||||
|
||||
public init(configurationVersion: Binding<Int>) {
|
||||
_configurationVersion = configurationVersion
|
||||
}
|
||||
public init() {}
|
||||
|
||||
public var body: some View {
|
||||
#if os(macOS)
|
||||
@@ -41,7 +38,6 @@ import SwiftUI
|
||||
Button("Reset", role: .destructive) {
|
||||
Task {
|
||||
await configuration.resetToDefault()
|
||||
configurationVersion += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,11 +45,9 @@ import SwiftUI
|
||||
Button("Done") {
|
||||
dismiss()
|
||||
}
|
||||
.keyboardShortcut(.escape, modifiers: [])
|
||||
}
|
||||
}
|
||||
.onExitCommand {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
#else
|
||||
private var iOSBody: some View {
|
||||
@@ -74,7 +68,6 @@ import SwiftUI
|
||||
Button("Reset", role: .destructive) {
|
||||
Task {
|
||||
await configuration.resetToDefault()
|
||||
configurationVersion += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,13 +84,13 @@ import SwiftUI
|
||||
isEnabled: configuration.isEnabled(card),
|
||||
onToggle: {
|
||||
configuration.toggleCard(card)
|
||||
configurationVersion += 1
|
||||
}
|
||||
)
|
||||
}
|
||||
.onMove { source, destination in
|
||||
configuration.moveCard(from: source, to: destination)
|
||||
configurationVersion += 1
|
||||
Task {
|
||||
await configuration.moveCard(from: source, to: destination)
|
||||
}
|
||||
}
|
||||
}
|
||||
.applyContentMargins()
|
||||
|
||||
@@ -40,13 +40,9 @@ public final class DashboardCardConfiguration: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
public func moveCard(from source: IndexSet, to destination: Int) {
|
||||
public func moveCard(from source: IndexSet, to destination: Int) async {
|
||||
cardOrder.move(fromOffsets: source, toOffset: destination)
|
||||
|
||||
// Save asynchronously in background
|
||||
Task {
|
||||
await saveCardOrder()
|
||||
}
|
||||
await saveCardOrder()
|
||||
}
|
||||
|
||||
public func resetToDefault() async {
|
||||
|
||||
@@ -19,12 +19,17 @@ public struct HTTPProxyCard: View {
|
||||
|
||||
public var body: some View {
|
||||
DashboardCardView(title: "", isHalfWidth: false) {
|
||||
Toggle("System HTTP Proxy", isOn: $systemProxyEnabled)
|
||||
.onChangeCompat(of: systemProxyEnabled) { newValue in
|
||||
Task {
|
||||
await onToggle(newValue)
|
||||
HStack {
|
||||
Text("System HTTP Proxy")
|
||||
Spacer()
|
||||
Toggle("", isOn: $systemProxyEnabled)
|
||||
.labelsHidden()
|
||||
.onChangeCompat(of: systemProxyEnabled) { newValue in
|
||||
Task {
|
||||
await onToggle(newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ public struct ProfileCard: View {
|
||||
.disabled(viewModel.isUpdating)
|
||||
.sheet(isPresented: $viewModel.showNewProfile, onDismiss: {
|
||||
environments.profileUpdate.send()
|
||||
}) {
|
||||
}, content: {
|
||||
NewProfileNavigationView()
|
||||
.environmentObject(environments)
|
||||
}
|
||||
})
|
||||
.sheet(isPresented: $viewModel.showManageProfiles) {
|
||||
manageProfilesSheet
|
||||
}
|
||||
@@ -218,11 +218,12 @@ public struct ProfileCard: View {
|
||||
NavigationSheet(
|
||||
title: String(localized: "Manage profiles"),
|
||||
showDoneButton: true,
|
||||
onDismiss: { viewModel.showManageProfiles = false }
|
||||
) {
|
||||
ManageProfilesView()
|
||||
.environmentObject(environments)
|
||||
}
|
||||
onDismiss: { viewModel.showManageProfiles = false },
|
||||
content: {
|
||||
ManageProfilesView()
|
||||
.environmentObject(environments)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
@@ -390,6 +391,7 @@ extension ProfileCard {
|
||||
@ObservedObject private var viewModel: ProfileViewModel
|
||||
@State private var profile: ProfilePreview
|
||||
@State private var shareLinkPresented = false
|
||||
@State private var isUpdating = false
|
||||
|
||||
init(_ viewModel: ProfileViewModel, _ profile: ProfilePreview) {
|
||||
self.viewModel = viewModel
|
||||
@@ -416,25 +418,26 @@ extension ProfileCard {
|
||||
HStack(spacing: 8) {
|
||||
if profile.type == .remote {
|
||||
Button {
|
||||
viewModel.isUpdating = true
|
||||
isUpdating = true
|
||||
Task {
|
||||
await viewModel.updateProfile(profile.origin)
|
||||
profile = ProfilePreview(profile.origin)
|
||||
isUpdating = false
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
.font(.system(size: 16))
|
||||
.rotationEffect(.degrees(viewModel.isUpdating ? 360 : 0))
|
||||
.rotationEffect(.degrees(isUpdating ? 360 : 0))
|
||||
.animation(
|
||||
viewModel.isUpdating
|
||||
isUpdating
|
||||
? .linear(duration: 1).repeatForever(autoreverses: false)
|
||||
: .default,
|
||||
value: viewModel.isUpdating
|
||||
value: isUpdating
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.actionButtonStyle()
|
||||
.disabled(viewModel.isUpdating)
|
||||
.disabled(isUpdating)
|
||||
|
||||
Button {
|
||||
shareLinkPresented = true
|
||||
|
||||
@@ -83,10 +83,8 @@ struct ProfileSelectorButton: View {
|
||||
|
||||
private func updateButtonContent(_ button: MenuAttachmentButton) {
|
||||
// Remove existing subviews
|
||||
for subview in button.subviews {
|
||||
if subview is UIStackView {
|
||||
subview.removeFromSuperview()
|
||||
}
|
||||
for subview in button.subviews where subview is UIStackView {
|
||||
subview.removeFromSuperview()
|
||||
}
|
||||
|
||||
// Create content stack
|
||||
|
||||
Reference in New Issue
Block a user