diff --git a/Sources/PackAPrefPane/PrefPaneData.swift b/Sources/PackAPrefPane/PrefPaneData.swift index 37dcbdb..5a617ed 100644 --- a/Sources/PackAPrefPane/PrefPaneData.swift +++ b/Sources/PackAPrefPane/PrefPaneData.swift @@ -38,7 +38,7 @@ public struct PrefPaneData { public let legalSectionData: LegalSectionData } /// Type to group help section data -public struct HelpSectionData { +public class HelpSectionData: ObservableObject { /// ``HelpSectionData`` public initializer for swift package usage /// - Parameters: /// - showHelpSection: ``HelpSectionData/showHelpSection`` @@ -129,7 +129,7 @@ public struct FrequentlyAskedQuestions: Identifiable { public let answer: String } /// Type to group about section data -public struct AboutSectionData { +public class AboutSectionData: ObservableObject { /// ``AboutSectionData`` public initializer for swift package usage /// - Parameters: /// - developerInfoText: ``AboutSectionData/developerInfoText`` @@ -196,7 +196,7 @@ public struct ThirdPartyCode: Identifiable { public let sourceLicenseText: String } /// Type to group legal section data -public struct LegalSectionData { +public class LegalSectionData: ObservableObject { /// ``LegalSectionData`` public initializer for swift package usage /// - Parameters: /// - showLegalSection: ``LegalSectionData/showLegalSection`` diff --git a/Sources/PackAPrefPane/Views/Help.swift b/Sources/PackAPrefPane/Views/Help.swift index a85e2fd..a07b96c 100644 --- a/Sources/PackAPrefPane/Views/Help.swift +++ b/Sources/PackAPrefPane/Views/Help.swift @@ -16,25 +16,25 @@ public struct Help: View { public var body: some View { Section(header: Text(NSLocalizedString("🆘 Help", tableName: "Localizable", bundle: .module, value: "", comment: ""))) { if helpSectionData.showFeedbackLink { - Feedback(helpSectionData: helpSectionData) + Feedback() } if helpSectionData.showSupportLink { - Support(helpSectionData: helpSectionData) + Support() } if helpSectionData.showWhatsNew { - WhatsNew(helpSectionData: helpSectionData) + WhatsNew() } if helpSectionData.showFAQ { FAQ(faq: helpSectionData.faq) } - } + }.environmentObject(helpSectionData) } } // MARK: - Feedback @available(macOS 11.0, iOS 14, *) struct Feedback: View { // Variables - let helpSectionData: HelpSectionData + @EnvironmentObject var helpSectionData: HelpSectionData // UI var body: some View { Link(destination: PrefPaneHelper.appFeedbackURL(for: helpSectionData.appID)) { @@ -50,7 +50,7 @@ struct Feedback: View { @available(macOS 11.0, iOS 14, *) struct Support: View { // Variables - let helpSectionData: HelpSectionData + @EnvironmentObject var helpSectionData: HelpSectionData // UI var body: some View { Link(destination: PrefPaneHelper.supportEmailURL( @@ -72,7 +72,7 @@ struct Support: View { struct WhatsNew: View { // Variables @State private var whatsNewExpanded: Bool = false - let helpSectionData: HelpSectionData + @EnvironmentObject var helpSectionData: HelpSectionData let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String // UI var body: some View { diff --git a/Sources/PackAPrefPane/Views/Legal.swift b/Sources/PackAPrefPane/Views/Legal.swift index 27fb570..b515255 100644 --- a/Sources/PackAPrefPane/Views/Legal.swift +++ b/Sources/PackAPrefPane/Views/Legal.swift @@ -25,24 +25,26 @@ public struct Legal: View { if legalSectionData.showDisclaimer { Disclaimer( alertPresented: $alertPresented, - alert: $alert, - legalSectionData: legalSectionData + alert: $alert ) } if legalSectionData.showPrivacyPolicy { PrivacyPolicy( alertPresented: $alertPresented, - alert: $alert, - legalSectionData: legalSectionData + alert: $alert ) } if legalSectionData.showAcknowledgments { - Acknowledgments(alertPresented: $alertPresented, alert: $alert) + Acknowledgments( + alertPresented: $alertPresented, + alert: $alert + ) } if legalSectionData.showTOS { - TermsOfService(legalSectionData: legalSectionData) + TermsOfService() } - }.alert(isPresented: $alertPresented, content: { // alert switch cases + }.environmentObject(legalSectionData) + .alert(isPresented: $alertPresented, content: { // alert switch cases switch alert { case .disclaimerAlert: return Alert( @@ -86,7 +88,7 @@ struct Disclaimer: View { // Variables @Binding var alertPresented: Bool @Binding var alert: Legal.alerts - let legalSectionData: LegalSectionData + @EnvironmentObject var legalSectionData: LegalSectionData // UI var body: some View { Button(action: { @@ -115,7 +117,7 @@ struct PrivacyPolicy: View { // Variables @Binding var alertPresented: Bool @Binding var alert: Legal.alerts - let legalSectionData: LegalSectionData + @EnvironmentObject var legalSectionData: LegalSectionData // UI var body: some View { Button(action: { @@ -164,7 +166,7 @@ struct Acknowledgments: View { struct TermsOfService: View { // Variables @State private var tosExpanded: Bool = false - let legalSectionData: LegalSectionData + @EnvironmentObject var legalSectionData: LegalSectionData // UI var body: some View { DisclosureGroup(NSLocalizedString("Terms of Service", tableName: "Localizable", bundle: .module, value: "", comment: ""), isExpanded: $tosExpanded) { diff --git a/Sources/PackAPrefPane/Views/PackAPrefPane.swift b/Sources/PackAPrefPane/Views/PackAPrefPane.swift index e173a83..9423acd 100644 --- a/Sources/PackAPrefPane/Views/PackAPrefPane.swift +++ b/Sources/PackAPrefPane/Views/PackAPrefPane.swift @@ -38,11 +38,15 @@ public struct PackAPrefPane: View { public var body: some View { NavigationView { Form { + // Your app settings section view appSettingsView + // Optionnal Help section view if prefPaneData.helpSectionData.showHelpSection { Help(helpSectionData: prefPaneData.helpSectionData) } + // Mandatory About section view About(aboutSectionData: prefPaneData.aboutSectionData) + // Optionnal Legal section view if prefPaneData.legalSectionData.showLegalSection { Legal(legalSectionData: prefPaneData.legalSectionData) }