Improve JSON editor for macOS

This commit is contained in:
世界
2025-11-26 22:25:52 +08:00
parent 3f1c716a0a
commit c5fd6a6b4e
25 changed files with 979 additions and 322 deletions
@@ -11,20 +11,65 @@ import SwiftUI
}
public var body: some View {
NavigationStackCompat {
Group {
if configuration.isLoading {
ProgressView()
} else {
listContent
#if os(macOS)
macOSBody
#else
iOSBody
#endif
}
#if os(macOS)
private var macOSBody: some View {
VStack(alignment: .leading, spacing: 0) {
Text("Dashboard Items")
.font(.headline)
.padding(.horizontal, 20)
.padding(.top, 20)
.padding(.bottom, 12)
Group {
if configuration.isLoading {
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
listContent
}
}
}
.navigationTitle("Dashboard Items")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.toolbar {
#if os(iOS) || os(tvOS)
.toolbar {
ToolbarItem(placement: .destructiveAction) {
Button("Reset", role: .destructive) {
Task {
await configuration.resetToDefault()
configurationVersion += 1
}
}
}
ToolbarItem(placement: .confirmationAction) {
Button("Done") {
dismiss()
}
}
}
.onExitCommand {
dismiss()
}
}
#else
private var iOSBody: some View {
NavigationStackCompat {
Group {
if configuration.isLoading {
ProgressView()
} else {
listContent
}
}
.navigationTitle("Dashboard Items")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Reset", role: .destructive) {
Task {
@@ -33,24 +78,10 @@ import SwiftUI
}
}
}
#else
ToolbarItem(placement: .cancellationAction) {
Button("Reset", role: .destructive) {
Task {
await configuration.resetToDefault()
configurationVersion += 1
}
}
}
ToolbarItem(placement: .confirmationAction) {
Button("Done") {
dismiss()
}
}
#endif
}
}
}
}
}
#endif
private var listContent: some View {
List {
@@ -216,7 +216,7 @@ public struct ProfileCard: View {
private var manageProfilesSheet: some View {
NavigationSheet(
title: "Profiles",
title: String(localized: "Manage profiles"),
showDoneButton: true,
onDismiss: { viewModel.showManageProfiles = false }
) {
@@ -227,11 +227,20 @@ public struct ProfileCard: View {
@ViewBuilder
private func editProfileSheet(for profile: Profile) -> some View {
NavigationSheet(title: "Edit Profile") {
EditProfileView()
.environmentObject(profile)
.environmentObject(environments)
}
#if os(macOS)
NavigationSheet {
EditProfileView()
.environmentObject(profile)
.environmentObject(environments)
}
.frame(minWidth: 500, minHeight: 400)
#else
NavigationSheet(title: "Edit Profile") {
EditProfileView()
.environmentObject(profile)
.environmentObject(environments)
}
#endif
}
}
@@ -272,7 +281,16 @@ extension ProfileCard {
@State private var createdProfile: Profile?
var body: some View {
NavigationStackCompat {
#if os(macOS)
macOSBody
#else
iOSBody
#endif
}
#if os(macOS)
@ViewBuilder
private var macOSBody: some View {
if let profile = createdProfile {
EditProfileView()
.environmentObject(profile)
@@ -282,15 +300,28 @@ extension ProfileCard {
createdProfile = profile
}
.environmentObject(environments)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
}
#if os(iOS) || os(tvOS)
.presentationDetentsIfAvailable()
#endif
}
#else
private var iOSBody: some View {
NavigationStackCompat {
if let profile = createdProfile {
EditProfileView()
.environmentObject(profile)
.environmentObject(environments)
} else {
NewProfileView { profile in
createdProfile = profile
}
.environmentObject(environments)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
}
.presentationDetentsIfAvailable()
}
#endif
}
}
@@ -305,12 +336,14 @@ extension ProfileCard {
var body: some View {
VStack {
if viewModel.isLoading {
ProgressView().onAppear {
viewModel.setEnvironments(environments)
Task {
await viewModel.doReload()
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onAppear {
viewModel.setEnvironments(environments)
Task {
await viewModel.doReload()
}
}
}
} else {
FormView {
if viewModel.profileList.isEmpty {